From eda41ff07bf89f409e41f00872efd0e325a12744 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:29:10 +0200 Subject: [PATCH 01/45] chore: make /tests participate in type checking --- src/Testing/TestAgentFactory.ts | 6 ++- src/application/create-application.ts | 3 +- .../definition/resolve-route-options.ts | 7 +-- src/routing/helpers/route-group.ts | 7 ++- .../registration/expand-route-definitions.ts | 15 ++++-- src/routing/registration/register-routes.ts | 14 ++++-- .../registration/route-registration.ts | 10 +++- src/routing/source/normalize-route-sources.ts | 49 ++++++++++++------- .../validation/validate-route-definitions.ts | 10 ++-- src/routing/verify-routing-mode.ts | 3 +- tests/tsconfig.json | 9 ++++ 11 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 tests/tsconfig.json diff --git a/src/Testing/TestAgentFactory.ts b/src/Testing/TestAgentFactory.ts index 9695fb1..80c1abd 100644 --- a/src/Testing/TestAgentFactory.ts +++ b/src/Testing/TestAgentFactory.ts @@ -2,10 +2,14 @@ import { create } from '@/application/create-application'; import { type KoalaConfig } from '@/config/koala-config'; import { type HttpMiddleware, type HttpScope, type NextMiddleware } from '@/Http'; import { type User } from '@/Security/types'; +import type { Request } from 'koa'; import supertest from 'supertest'; import { type TestAgent } from './types'; -export function createTestAgent(config: KoalaConfig, agentConfig?: { actAs?: User }): TestAgent { +export function createTestAgent( + config: KoalaConfig, + agentConfig?: { actAs?: User }, +): TestAgent { const globalMiddleware = config.globalMiddleware ?? []; const testConfig = { ...config }; diff --git a/src/application/create-application.ts b/src/application/create-application.ts index be225a5..8d98d22 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -8,9 +8,10 @@ import { registerLegacyRoutes } from '@/routing/decorator/legacy-router'; import { registerRoutes } from '@/routing/registration/register-routes'; import { verifyRoutingMode } from '@/routing/verify-routing-mode'; import Koa from 'koa'; +import type { Request } from 'koa'; import { type Application } from './application'; -export function create(config: KoalaConfig): Application { +export function create(config: KoalaConfig): Application { const app = new Koa() as Application; const controllers = config.controllers ?? []; diff --git a/src/routing/definition/resolve-route-options.ts b/src/routing/definition/resolve-route-options.ts index b5a6d28..53d821d 100644 --- a/src/routing/definition/resolve-route-options.ts +++ b/src/routing/definition/resolve-route-options.ts @@ -1,4 +1,5 @@ import type { RouteOptions } from '@/routing/route-options'; +import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition'; export function resolveRouteOptions(options: RouteOptions): Pick { @@ -8,10 +9,10 @@ export function resolveRouteOptions(options: RouteOptions): Pick( + route: RouteDefinition, options: RouteOptions, -): Pick { +): Pick, 'parseBody' | 'bodyOptions'> { return { parseBody: options.parseBody ?? route.parseBody, bodyOptions: { diff --git a/src/routing/helpers/route-group.ts b/src/routing/helpers/route-group.ts index aef2803..a282153 100644 --- a/src/routing/helpers/route-group.ts +++ b/src/routing/helpers/route-group.ts @@ -3,13 +3,16 @@ import type { RouteDeclaration } from '@/routing/route'; import type { RouteSource } from '@/routing/source/route-source'; import type { Request } from 'koa'; -export type RouteConfigOverlay = Pick; +export type RouteConfigOverlay = Pick< + RouteDeclaration, + 'middleware' | 'options' +>; export interface RouteGroupOptions { prefix?: string; namePrefix?: string; middleware?: HttpMiddleware[]; - routeConfig?: Record; + routeConfig?: Record>; } export interface RouteGroupDefinition { diff --git a/src/routing/registration/expand-route-definitions.ts b/src/routing/registration/expand-route-definitions.ts index cea4d49..2b88d9f 100644 --- a/src/routing/registration/expand-route-definitions.ts +++ b/src/routing/registration/expand-route-definitions.ts @@ -1,9 +1,12 @@ import { koaBody } from 'koa-body'; +import type { Request } from 'koa'; import type { RouteDefinition } from '@/routing/definition/route-definition'; import type { RouteRegistration } from '@/routing/registration/route-registration'; -export function expandRouteDefinitions(routes: RouteDefinition[]): RouteRegistration[] { - const registrations: RouteRegistration[] = []; +export function expandRouteDefinitions( + routes: RouteDefinition[], +): RouteRegistration[] { + const registrations: RouteRegistration[] = []; for (const route of routes) { registrations.push(...expandRouteDefinition(route)); @@ -12,7 +15,9 @@ export function expandRouteDefinitions(routes: RouteDefinition[]): RouteRegistra return registrations; } -function expandRouteDefinition(route: RouteDefinition): RouteRegistration[] { +function expandRouteDefinition( + route: RouteDefinition, +): RouteRegistration[] { const middleware = resolveRouteMiddleware(route); return route.methods.map(method => ({ @@ -22,7 +27,9 @@ function expandRouteDefinition(route: RouteDefinition): RouteRegistration[] { })); } -function resolveRouteMiddleware(route: RouteDefinition): RouteRegistration['middleware'] { +function resolveRouteMiddleware( + route: RouteDefinition, +): RouteRegistration['middleware'] { const middlewareStack = [...route.middleware, route.handler]; return route.parseBody ? [koaBody(route.bodyOptions), ...middlewareStack] : middlewareStack; diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index f70f9ea..17e8e40 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -4,10 +4,13 @@ import { expandRouteDefinitions } from '@/routing/registration/expand-route-defi import { normalizeRouteSources } from '@/routing/source/normalize-route-sources'; import type { RouteSource } from '@/routing/source/route-source'; import { validateRouteDefinitions } from '@/routing/validation/validate-route-definitions'; -import { type DefaultContext, type DefaultState, type Middleware } from 'koa'; +import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; import Router, { type RouterInstance } from '@koa/router'; -export function registerRoutes(app: Application, routes: RouteSource[] = []): Application { +export function registerRoutes( + app: Application, + routes: RouteSource[] = [], +): Application { const router = createRouter(routes); app.use(router.routes() as unknown as Middleware); @@ -16,7 +19,7 @@ export function registerRoutes(app: Application, routes: RouteSource[] = []): Ap return app; } -function createRouter(routeSources: RouteSource[]): RouterInstance { +function createRouter(routeSources: RouteSource[]): RouterInstance { const router = new Router(); const routes = normalizeRouteSources(routeSources); const registrations = expandRouteDefinitions(routes); @@ -24,7 +27,10 @@ function createRouter(routeSources: RouteSource[]): RouterInstance { validateRouteDefinitions(routes, registrations); for (const route of registrations) { - router[route.method](route.path, ...(route.middleware as Middleware[])); + router[route.method]( + route.path, + ...(route.middleware as unknown as Middleware[]), + ); } return router; diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index cf0af3e..d05c9bd 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,8 +1,14 @@ +import type { HttpRequest } from '@/Http'; import type { RouteDefinition } from '@/routing/definition/route-definition'; import type { RouterMethod } from '@/routing/router-method'; +import type { Request } from 'koa'; -export interface RouteRegistration { +type RouteRegistrationMiddleware = + | RouteDefinition['middleware'][number] + | RouteDefinition['handler']; + +export interface RouteRegistration { method: RouterMethod; path: string; - middleware: Array; + middleware: RouteRegistrationMiddleware[]; } diff --git a/src/routing/source/normalize-route-sources.ts b/src/routing/source/normalize-route-sources.ts index a1ee210..616a25c 100644 --- a/src/routing/source/normalize-route-sources.ts +++ b/src/routing/source/normalize-route-sources.ts @@ -1,25 +1,26 @@ import type { RouteDefinition } from '@/routing/definition/route-definition'; import { mergeRouteOptions } from '@/routing/definition/resolve-route-options'; import type { RouteGroupDefinition } from '@/routing/helpers/route-group'; +import type { Request } from 'koa'; import type { RouteSource } from './route-source'; -interface NormalizationContext { +interface NormalizationContext { prefix: string; namePrefix: string; - middleware: RouteDefinition['middleware']; + middleware: RouteDefinition['middleware']; } -const defaultNormalizationContext: NormalizationContext = { +const defaultNormalizationContext = { prefix: '', namePrefix: '', middleware: [], }; -export function normalizeRouteSources( - routeSources: RouteSource[], - context: NormalizationContext = defaultNormalizationContext, -): RouteDefinition[] { - const routes: RouteDefinition[] = []; +export function normalizeRouteSources( + routeSources: RouteSource[], + context: NormalizationContext = defaultNormalizationContext, +): RouteDefinition[] { + const routes: RouteDefinition[] = []; for (const routeSource of routeSources) { if (isRouteGroupDefinition(routeSource)) { @@ -33,13 +34,19 @@ export function normalizeRouteSources( return routes; } -function normalizeRouteGroup(group: RouteGroupDefinition, parentContext: NormalizationContext): RouteDefinition[] { +function normalizeRouteGroup( + group: RouteGroupDefinition, + parentContext: NormalizationContext, +): RouteDefinition[] { const context = createChildContext(group, parentContext); return normalizeRouteSources(applyRouteConfig(group.resolveRoutes(), group), context); } -function createChildContext(group: RouteGroupDefinition, parentContext: NormalizationContext): NormalizationContext { +function createChildContext( + group: RouteGroupDefinition, + parentContext: NormalizationContext, +): NormalizationContext { return { prefix: group.options.prefix === undefined @@ -50,7 +57,10 @@ function createChildContext(group: RouteGroupDefinition, parentContext: Normaliz }; } -function normalizeRouteDefinition(route: RouteDefinition, context: NormalizationContext): RouteDefinition { +function normalizeRouteDefinition( + route: RouteDefinition, + context: NormalizationContext, +): RouteDefinition { return { ...route, path: joinRoutePath(context.prefix, route.path), @@ -59,7 +69,10 @@ function normalizeRouteDefinition(route: RouteDefinition, context: Normalization }; } -function applyRouteConfig(routeSources: RouteSource[], group: RouteGroupDefinition): RouteSource[] { +function applyRouteConfig( + routeSources: RouteSource[], + group: RouteGroupDefinition, +): RouteSource[] { return routeSources.map(routeSource => { if (isRouteGroupDefinition(routeSource)) { return routeSource; @@ -79,14 +92,16 @@ function applyRouteConfig(routeSources: RouteSource[], group: RouteGroupDefiniti }); } -function resolveRouteConfigOptions( - route: RouteDefinition, - routeConfig: NonNullable[string], -): Partial> { +function resolveRouteConfigOptions( + route: RouteDefinition, + routeConfig: NonNullable['options']['routeConfig']>[string], +): Partial, 'parseBody' | 'bodyOptions'>> { return routeConfig.options ? mergeRouteOptions(route, routeConfig.options) : {}; } -function isRouteGroupDefinition(routeSource: RouteSource): routeSource is RouteGroupDefinition { +function isRouteGroupDefinition( + routeSource: RouteSource, +): routeSource is RouteGroupDefinition { return 'kind' in routeSource && routeSource.kind === 'route-group'; } diff --git a/src/routing/validation/validate-route-definitions.ts b/src/routing/validation/validate-route-definitions.ts index 2284733..a4f4fb4 100644 --- a/src/routing/validation/validate-route-definitions.ts +++ b/src/routing/validation/validate-route-definitions.ts @@ -1,12 +1,16 @@ import type { RouteDefinition } from '@/routing/definition/route-definition'; import type { RouteRegistration } from '@/routing/registration/route-registration'; +import type { Request } from 'koa'; -export function validateRouteDefinitions(routes: RouteDefinition[], registrations: RouteRegistration[]): void { +export function validateRouteDefinitions( + routes: RouteDefinition[], + registrations: RouteRegistration[], +): void { validateUniqueRouteNames(routes); validateUniqueRouteSignatures(registrations); } -function validateUniqueRouteSignatures(registrations: RouteRegistration[]): void { +function validateUniqueRouteSignatures(registrations: RouteRegistration[]): void { const signatures = new Set(); for (const registration of registrations) { @@ -20,7 +24,7 @@ function validateUniqueRouteSignatures(registrations: RouteRegistration[]): void } } -function validateUniqueRouteNames(routes: RouteDefinition[]): void { +function validateUniqueRouteNames(routes: RouteDefinition[]): void { const routeNames = new Set(); for (const route of routes) { diff --git a/src/routing/verify-routing-mode.ts b/src/routing/verify-routing-mode.ts index 8fa2ec5..993beaf 100644 --- a/src/routing/verify-routing-mode.ts +++ b/src/routing/verify-routing-mode.ts @@ -1,9 +1,10 @@ import type { KoalaConfig } from '@/config/koala-config'; +import type { Request } from 'koa'; export const exclusiveRoutingModeError = 'Koala routing mode is exclusive. Use either legacy controllers from @koala-ts/framework or routes from @koala-ts/framework/routing.'; -export function verifyRoutingMode(config: KoalaConfig): void { +export function verifyRoutingMode(config: KoalaConfig): void { const controllers = config.controllers ?? []; if (config.routes !== undefined && controllers.length > 0) { diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..45e73fa --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": ".." + }, + "include": ["../src/**/*.ts", "../src/**/*.d.ts", "./**/*.ts", "./**/*.d.ts"], + "exclude": ["../node_modules", "../dist", "../coverage"] +} From 1023dfe608575f84c03d633f58b409aec1f9e12f Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:31:02 +0200 Subject: [PATCH 02/45] chore: add watch scripts --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b0a9ff6..dbb27c5 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,9 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --write .", - "format:check": "prettier --check ." + "format:check": "prettier --check .", + "watch:test": "vitest watch", + "watch:build": "tsc --noEmit --watch" }, "dependencies": { "@koa/router": "^15.1.1", From 4570dd14e600233ec89cddd1645b80f01c0550a6 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:31:37 +0200 Subject: [PATCH 03/45] wip: simplify imports --- tests/function-first-routing.e2e.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/function-first-routing.e2e.test.ts b/tests/function-first-routing.e2e.test.ts index 086af08..c5e253c 100644 --- a/tests/function-first-routing.e2e.test.ts +++ b/tests/function-first-routing.e2e.test.ts @@ -1,10 +1,10 @@ +import { koalaDefaultConfig } from '@/config/default-config'; +import type { HttpMiddleware, HttpRequest, HttpScope, NextMiddleware, UploadedFile } from '@/Http'; +import { Any, Get, Post, Route, RouteGroup } from '@/routing'; +import { exclusiveRoutingModeError } from '@/routing/verify-routing-mode'; +import { createTestAgent } from '@/Testing'; import { text } from 'node:stream/consumers'; import { describe, expect, test } from 'vitest'; -import { koalaDefaultConfig } from '../src/config/default-config'; -import type { HttpMiddleware, HttpRequest, HttpScope, NextMiddleware, UploadedFile } from '../src/Http'; -import { Any, Get, Post, Route, RouteGroup } from '../src/routing'; -import { createTestAgent } from '../src/Testing/TestAgentFactory'; -import { exclusiveRoutingModeError } from '../src/routing/verify-routing-mode'; interface FunctionFirstRoutingRequest extends HttpRequest { body: { name: string }; From a8211b32bd30290f2d20c3d6a14f579c666d4e40 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:47:09 +0200 Subject: [PATCH 04/45] wip: rename legacy decorator --- src/application/create-application.ts | 4 ++-- src/index.ts | 6 +++--- .../{decorator => legacy-decorator}/legacy-router.test.ts | 0 .../{decorator => legacy-decorator}/legacy-router.ts | 0 .../{decorator => legacy-decorator}/route-metadata.ts | 0 src/routing/{decorator => legacy-decorator}/route.ts | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename src/routing/{decorator => legacy-decorator}/legacy-router.test.ts (100%) rename src/routing/{decorator => legacy-decorator}/legacy-router.ts (100%) rename src/routing/{decorator => legacy-decorator}/route-metadata.ts (100%) rename src/routing/{decorator => legacy-decorator}/route.ts (100%) diff --git a/src/application/create-application.ts b/src/application/create-application.ts index 8d98d22..db6f935 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -4,11 +4,11 @@ import { serveStaticFiles } from '@/Http/Files'; import { applyConfiguredGlobalMiddleware } from '@/Http/middleware/apply-configured-global-middleware'; import { initializeRequestScopeStorage } from '@/Http/Scope/request-scope-storage'; import { registerEventSubscribers } from '@/Kernel'; -import { registerLegacyRoutes } from '@/routing/decorator/legacy-router'; +import { registerLegacyRoutes } from '@/routing/legacy-decorator/legacy-router'; import { registerRoutes } from '@/routing/registration/register-routes'; import { verifyRoutingMode } from '@/routing/verify-routing-mode'; -import Koa from 'koa'; import type { Request } from 'koa'; +import Koa from 'koa'; import { type Application } from './application'; export function create(config: KoalaConfig): Application { diff --git a/src/index.ts b/src/index.ts index 74f40f9..99a5a75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ // Application export { create } from '@/application/create-application'; export type { Application } from '@/application/application'; -import { getLegacyRoutes, registerLegacyRoutes } from '@/routing/decorator/legacy-router'; -import type { RouteMetadata as LegacyRouteMetadata } from '@/routing/decorator/route-metadata'; +import { getLegacyRoutes, registerLegacyRoutes } from '@/routing/legacy-decorator/legacy-router'; +import type { RouteMetadata as LegacyRouteMetadata } from '@/routing/legacy-decorator/route-metadata'; // Core modules export type * from '@/config/koala-config'; @@ -12,7 +12,7 @@ export * from '@/Http'; export * from '@/Kernel'; // Routing -export * from '@/routing/decorator/route'; +export * from '@/routing/legacy-decorator/route'; export type { HttpMethod } from '@/routing/http-method'; export type { RouteOptions } from '@/routing/route-options'; export type { RouterMethod } from '@/routing/router-method'; diff --git a/src/routing/decorator/legacy-router.test.ts b/src/routing/legacy-decorator/legacy-router.test.ts similarity index 100% rename from src/routing/decorator/legacy-router.test.ts rename to src/routing/legacy-decorator/legacy-router.test.ts diff --git a/src/routing/decorator/legacy-router.ts b/src/routing/legacy-decorator/legacy-router.ts similarity index 100% rename from src/routing/decorator/legacy-router.ts rename to src/routing/legacy-decorator/legacy-router.ts diff --git a/src/routing/decorator/route-metadata.ts b/src/routing/legacy-decorator/route-metadata.ts similarity index 100% rename from src/routing/decorator/route-metadata.ts rename to src/routing/legacy-decorator/route-metadata.ts diff --git a/src/routing/decorator/route.ts b/src/routing/legacy-decorator/route.ts similarity index 100% rename from src/routing/decorator/route.ts rename to src/routing/legacy-decorator/route.ts From 23f2004371e851e74d2fb1234dacdcd19c4dfadb Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:55:08 +0200 Subject: [PATCH 05/45] wip: trim public api --- src/routing/index.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/routing/index.ts b/src/routing/index.ts index 5c5e4d8..b990d1d 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -2,8 +2,3 @@ export { Route } from './route'; export { createPathFor } from './helpers/create-path-for'; export { RouteGroup } from './helpers/route-group'; export { Any, Delete, Get, Head, Options, Patch, Post, Put } from './helpers/http-verb-helpers'; -export type { RouteDeclaration } from './route'; -export type { RouteConfigOverlay, RouteGroupDefinition, RouteGroupOptions } from './helpers/route-group'; -export type { RouteSource } from './source/route-source'; -export type { HttpMethod } from './http-method'; -export type { RouteOptions } from './route-options'; From 771fc65e7b20f880b0d02a4aafa8b9c16b25bea4 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 20:58:25 +0200 Subject: [PATCH 06/45] wip: mark decorator as deprecated by dir name --- src/application/create-application.ts | 2 +- src/index.ts | 6 +++--- .../legacy-router.test.ts | 0 .../legacy-router.ts | 0 .../route-metadata.ts | 0 .../{legacy-decorator => deprecated-decorator}/route.ts | 0 6 files changed, 4 insertions(+), 4 deletions(-) rename src/routing/{legacy-decorator => deprecated-decorator}/legacy-router.test.ts (100%) rename src/routing/{legacy-decorator => deprecated-decorator}/legacy-router.ts (100%) rename src/routing/{legacy-decorator => deprecated-decorator}/route-metadata.ts (100%) rename src/routing/{legacy-decorator => deprecated-decorator}/route.ts (100%) diff --git a/src/application/create-application.ts b/src/application/create-application.ts index db6f935..84e51b6 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -4,7 +4,7 @@ import { serveStaticFiles } from '@/Http/Files'; import { applyConfiguredGlobalMiddleware } from '@/Http/middleware/apply-configured-global-middleware'; import { initializeRequestScopeStorage } from '@/Http/Scope/request-scope-storage'; import { registerEventSubscribers } from '@/Kernel'; -import { registerLegacyRoutes } from '@/routing/legacy-decorator/legacy-router'; +import { registerLegacyRoutes } from '@/routing/deprecated-decorator/legacy-router'; import { registerRoutes } from '@/routing/registration/register-routes'; import { verifyRoutingMode } from '@/routing/verify-routing-mode'; import type { Request } from 'koa'; diff --git a/src/index.ts b/src/index.ts index 99a5a75..695393b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ // Application export { create } from '@/application/create-application'; export type { Application } from '@/application/application'; -import { getLegacyRoutes, registerLegacyRoutes } from '@/routing/legacy-decorator/legacy-router'; -import type { RouteMetadata as LegacyRouteMetadata } from '@/routing/legacy-decorator/route-metadata'; +import { getLegacyRoutes, registerLegacyRoutes } from '@/routing/deprecated-decorator/legacy-router'; +import type { RouteMetadata as LegacyRouteMetadata } from '@/routing/deprecated-decorator/route-metadata'; // Core modules export type * from '@/config/koala-config'; @@ -12,7 +12,7 @@ export * from '@/Http'; export * from '@/Kernel'; // Routing -export * from '@/routing/legacy-decorator/route'; +export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/http-method'; export type { RouteOptions } from '@/routing/route-options'; export type { RouterMethod } from '@/routing/router-method'; diff --git a/src/routing/legacy-decorator/legacy-router.test.ts b/src/routing/deprecated-decorator/legacy-router.test.ts similarity index 100% rename from src/routing/legacy-decorator/legacy-router.test.ts rename to src/routing/deprecated-decorator/legacy-router.test.ts diff --git a/src/routing/legacy-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts similarity index 100% rename from src/routing/legacy-decorator/legacy-router.ts rename to src/routing/deprecated-decorator/legacy-router.ts diff --git a/src/routing/legacy-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts similarity index 100% rename from src/routing/legacy-decorator/route-metadata.ts rename to src/routing/deprecated-decorator/route-metadata.ts diff --git a/src/routing/legacy-decorator/route.ts b/src/routing/deprecated-decorator/route.ts similarity index 100% rename from src/routing/legacy-decorator/route.ts rename to src/routing/deprecated-decorator/route.ts From 47a33ba1c4a8de20833f02bbe1b53c3fff58ca02 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:01:25 +0200 Subject: [PATCH 07/45] wip: move verifier to legacy decorator --- src/application/create-application.test.ts | 2 +- src/application/create-application.ts | 2 +- .../{ => deprecated-decorator}/verify-routing-mode.test.ts | 0 src/routing/{ => deprecated-decorator}/verify-routing-mode.ts | 0 tests/function-first-routing.e2e.test.ts | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename src/routing/{ => deprecated-decorator}/verify-routing-mode.test.ts (100%) rename src/routing/{ => deprecated-decorator}/verify-routing-mode.ts (100%) diff --git a/src/application/create-application.test.ts b/src/application/create-application.test.ts index 4e122b4..601ef5a 100644 --- a/src/application/create-application.test.ts +++ b/src/application/create-application.test.ts @@ -1,7 +1,7 @@ import { create } from '@/application/create-application'; import { koalaDefaultConfig } from '@/config/default-config'; import { Get, Route, RouteGroup } from '@/routing'; -import { exclusiveRoutingModeError } from '@/routing/verify-routing-mode'; +import { exclusiveRoutingModeError } from '@/routing/deprecated-decorator/verify-routing-mode'; import { expect, test } from 'vitest'; test('create app with default config', () => { diff --git a/src/application/create-application.ts b/src/application/create-application.ts index 84e51b6..fffe043 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -5,8 +5,8 @@ import { applyConfiguredGlobalMiddleware } from '@/Http/middleware/apply-configu import { initializeRequestScopeStorage } from '@/Http/Scope/request-scope-storage'; import { registerEventSubscribers } from '@/Kernel'; import { registerLegacyRoutes } from '@/routing/deprecated-decorator/legacy-router'; +import { verifyRoutingMode } from '@/routing/deprecated-decorator/verify-routing-mode'; import { registerRoutes } from '@/routing/registration/register-routes'; -import { verifyRoutingMode } from '@/routing/verify-routing-mode'; import type { Request } from 'koa'; import Koa from 'koa'; import { type Application } from './application'; diff --git a/src/routing/verify-routing-mode.test.ts b/src/routing/deprecated-decorator/verify-routing-mode.test.ts similarity index 100% rename from src/routing/verify-routing-mode.test.ts rename to src/routing/deprecated-decorator/verify-routing-mode.test.ts diff --git a/src/routing/verify-routing-mode.ts b/src/routing/deprecated-decorator/verify-routing-mode.ts similarity index 100% rename from src/routing/verify-routing-mode.ts rename to src/routing/deprecated-decorator/verify-routing-mode.ts diff --git a/tests/function-first-routing.e2e.test.ts b/tests/function-first-routing.e2e.test.ts index c5e253c..5596bbb 100644 --- a/tests/function-first-routing.e2e.test.ts +++ b/tests/function-first-routing.e2e.test.ts @@ -1,7 +1,7 @@ import { koalaDefaultConfig } from '@/config/default-config'; import type { HttpMiddleware, HttpRequest, HttpScope, NextMiddleware, UploadedFile } from '@/Http'; import { Any, Get, Post, Route, RouteGroup } from '@/routing'; -import { exclusiveRoutingModeError } from '@/routing/verify-routing-mode'; +import { exclusiveRoutingModeError } from '@/routing/deprecated-decorator/verify-routing-mode'; import { createTestAgent } from '@/Testing'; import { text } from 'node:stream/consumers'; import { describe, expect, test } from 'vitest'; From 15bdfc41e29c92c78ed3ba133e0833f6d8117973 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:05:44 +0200 Subject: [PATCH 08/45] wip: rename http method type --- src/index.ts | 2 +- src/routing/definition/create-route-definition.ts | 6 +++--- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/helpers/http-verb-helpers.ts | 2 +- src/routing/{http-method.ts => http-method.type.ts} | 0 src/routing/index.ts | 1 + src/routing/route.ts | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) rename src/routing/{http-method.ts => http-method.type.ts} (100%) diff --git a/src/index.ts b/src/index.ts index 695393b..586fdf8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; -export type { HttpMethod } from '@/routing/http-method'; +export type { HttpMethod } from '@/routing/http-method.type'; export type { RouteOptions } from '@/routing/route-options'; export type { RouterMethod } from '@/routing/router-method'; /** diff --git a/src/routing/definition/create-route-definition.ts b/src/routing/definition/create-route-definition.ts index 09ec1a0..29da0e0 100644 --- a/src/routing/definition/create-route-definition.ts +++ b/src/routing/definition/create-route-definition.ts @@ -1,10 +1,10 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { HttpMethod } from '@/routing/http-method'; -import type { RouteOptions } from '@/routing/route-options'; import { resolveRouteOptions } from '@/routing/definition/resolve-route-options'; +import type { HttpMethod } from '@/routing/http-method.type'; +import type { RouteOptions } from '@/routing/route-options'; import type { RouterMethod } from '@/routing/router-method'; -import type { RouteDefinition } from './route-definition'; import type { Request } from 'koa'; +import type { RouteDefinition } from './route-definition'; interface RouteDefinitionInput { name?: string; diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index 77e909e..9f39b46 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { HttpMethod } from '@/routing/http-method'; +import type { HttpMethod } from '@/routing/http-method.type'; import type { RouteOptions } from '@/routing/route-options'; import { createLegacyRouteDecorator } from './legacy-router'; diff --git a/src/routing/helpers/http-verb-helpers.ts b/src/routing/helpers/http-verb-helpers.ts index ed92cad..1debc41 100644 --- a/src/routing/helpers/http-verb-helpers.ts +++ b/src/routing/helpers/http-verb-helpers.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { HttpMethod } from '@/routing/http-method'; import type { RouteDefinition } from '@/routing/definition/route-definition'; +import type { HttpMethod } from '@/routing/http-method.type'; import { Route } from '@/routing/route'; import type { Request } from 'koa'; diff --git a/src/routing/http-method.ts b/src/routing/http-method.type.ts similarity index 100% rename from src/routing/http-method.ts rename to src/routing/http-method.type.ts diff --git a/src/routing/index.ts b/src/routing/index.ts index b990d1d..ec0b3b4 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,3 +1,4 @@ +export type { RouteSource } from '@/routing/source/route-source'; export { Route } from './route'; export { createPathFor } from './helpers/create-path-for'; export { RouteGroup } from './helpers/route-group'; diff --git a/src/routing/route.ts b/src/routing/route.ts index 3a6a74f..75657c0 100644 --- a/src/routing/route.ts +++ b/src/routing/route.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { createRouteDefinition } from '@/routing/definition/create-route-definition'; import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { HttpMethod } from '@/routing/http-method'; +import type { HttpMethod } from '@/routing/http-method.type'; import type { RouteOptions } from '@/routing/route-options'; import type { Request } from 'koa'; From af2ab246a8ec82b6fbbfe16cc68463d22abf068c Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:08:46 +0200 Subject: [PATCH 09/45] wip: move http-method to the verb concern --- src/index.ts | 2 +- src/routing/definition/create-route-definition.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/helpers/http-verb-helpers.ts | 2 +- src/routing/route.ts | 2 +- src/routing/{ => verb}/http-method.type.ts | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename src/routing/{ => verb}/http-method.type.ts (100%) diff --git a/src/index.ts b/src/index.ts index 586fdf8..c00e838 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; -export type { HttpMethod } from '@/routing/http-method.type'; +export type { HttpMethod } from '@/routing/verb/http-method.type'; export type { RouteOptions } from '@/routing/route-options'; export type { RouterMethod } from '@/routing/router-method'; /** diff --git a/src/routing/definition/create-route-definition.ts b/src/routing/definition/create-route-definition.ts index 29da0e0..3a12fe2 100644 --- a/src/routing/definition/create-route-definition.ts +++ b/src/routing/definition/create-route-definition.ts @@ -1,8 +1,8 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { resolveRouteOptions } from '@/routing/definition/resolve-route-options'; -import type { HttpMethod } from '@/routing/http-method.type'; import type { RouteOptions } from '@/routing/route-options'; import type { RouterMethod } from '@/routing/router-method'; +import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition'; diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index 9f39b46..fbc6cbe 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; -import type { HttpMethod } from '@/routing/http-method.type'; import type { RouteOptions } from '@/routing/route-options'; +import type { HttpMethod } from '@/routing/verb/http-method.type'; import { createLegacyRouteDecorator } from './legacy-router'; /** diff --git a/src/routing/helpers/http-verb-helpers.ts b/src/routing/helpers/http-verb-helpers.ts index 1debc41..222f209 100644 --- a/src/routing/helpers/http-verb-helpers.ts +++ b/src/routing/helpers/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { HttpMethod } from '@/routing/http-method.type'; import { Route } from '@/routing/route'; +import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; type RouteHandler = HttpMiddleware; diff --git a/src/routing/route.ts b/src/routing/route.ts index 75657c0..1ea67d2 100644 --- a/src/routing/route.ts +++ b/src/routing/route.ts @@ -1,8 +1,8 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { createRouteDefinition } from '@/routing/definition/create-route-definition'; import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { HttpMethod } from '@/routing/http-method.type'; import type { RouteOptions } from '@/routing/route-options'; +import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; export interface RouteDeclaration { diff --git a/src/routing/http-method.type.ts b/src/routing/verb/http-method.type.ts similarity index 100% rename from src/routing/http-method.type.ts rename to src/routing/verb/http-method.type.ts From 23bc53b96a320a5ab97a9524766283ae00ad0697 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:10:39 +0200 Subject: [PATCH 10/45] wip: rename type --- src/index.ts | 2 +- src/routing/definition/create-route-definition.ts | 2 +- src/routing/definition/route-definition.ts | 4 ++-- src/routing/deprecated-decorator/route-metadata.ts | 2 +- src/routing/registration/route-registration.ts | 2 +- src/routing/{router-method.ts => router-method.type.ts} | 0 6 files changed, 6 insertions(+), 6 deletions(-) rename src/routing/{router-method.ts => router-method.type.ts} (100%) diff --git a/src/index.ts b/src/index.ts index c00e838..50bde39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ export * from '@/Kernel'; export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/verb/http-method.type'; export type { RouteOptions } from '@/routing/route-options'; -export type { RouterMethod } from '@/routing/router-method'; +export type { RouterMethod } from '@/routing/router-method.type'; /** * @deprecated Use `Route` from `@koala-ts/framework/routing` instead. */ diff --git a/src/routing/definition/create-route-definition.ts b/src/routing/definition/create-route-definition.ts index 3a12fe2..634565d 100644 --- a/src/routing/definition/create-route-definition.ts +++ b/src/routing/definition/create-route-definition.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { resolveRouteOptions } from '@/routing/definition/resolve-route-options'; import type { RouteOptions } from '@/routing/route-options'; -import type { RouterMethod } from '@/routing/router-method'; +import type { RouterMethod } from '@/routing/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition'; diff --git a/src/routing/definition/route-definition.ts b/src/routing/definition/route-definition.ts index 8be96c9..5c5a67f 100644 --- a/src/routing/definition/route-definition.ts +++ b/src/routing/definition/route-definition.ts @@ -1,5 +1,5 @@ -import type { HttpRequest, HttpMiddleware } from '@/Http'; -import type { RouterMethod } from '@/routing/router-method'; +import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { RouterMethod } from '@/routing/router-method.type'; import type { Request } from 'koa'; import type { KoaBodyMiddlewareOptions } from 'koa-body'; diff --git a/src/routing/deprecated-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts index 5257621..42042fc 100644 --- a/src/routing/deprecated-decorator/route-metadata.ts +++ b/src/routing/deprecated-decorator/route-metadata.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; import type { RouteOptions } from '@/routing/route-options'; -import type { RouterMethod } from '@/routing/router-method'; +import type { RouterMethod } from '@/routing/router-method.type'; /** * @deprecated Legacy decorator routing metadata. Use `@koala-ts/framework/routing` instead. diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index d05c9bd..03e0c7c 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouterMethod } from '@/routing/router-method'; +import type { RouterMethod } from '@/routing/router-method.type'; import type { Request } from 'koa'; type RouteRegistrationMiddleware = diff --git a/src/routing/router-method.ts b/src/routing/router-method.type.ts similarity index 100% rename from src/routing/router-method.ts rename to src/routing/router-method.type.ts From 6c5178679016969d0ee2ca4a3e6a9bb99e776373 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:15:08 +0200 Subject: [PATCH 11/45] wip: consolidate based on concerns --- src/application/create-application.ts | 2 +- src/index.ts | 4 ++-- src/routing/deprecated-decorator/legacy-router.ts | 6 +++--- src/routing/deprecated-decorator/route-metadata.ts | 4 ++-- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/{helpers => group}/route-group.test.ts | 2 +- src/routing/{helpers => group}/route-group.ts | 4 ++-- src/routing/index.ts | 10 +++++----- src/routing/{helpers => path}/create-path-for.test.ts | 4 ++-- src/routing/{helpers => path}/create-path-for.ts | 6 +++--- .../definition/create-route-definition.test.ts | 0 .../{ => route}/definition/create-route-definition.ts | 6 +++--- .../definition/resolve-route-options.test.ts | 0 .../{ => route}/definition/resolve-route-options.ts | 2 +- src/routing/{ => route}/definition/route-definition.ts | 2 +- .../registration/expand-route-definitions.test.ts | 0 .../registration/expand-route-definitions.ts | 6 +++--- .../{ => route}/registration/register-routes.test.ts | 8 ++++---- .../{ => route}/registration/register-routes.ts | 10 +++++----- .../{ => route}/registration/route-registration.ts | 4 ++-- src/routing/{ => route}/route-options.ts | 0 src/routing/{ => route}/route.test.ts | 0 src/routing/{ => route}/route.ts | 6 +++--- src/routing/{ => route}/router-method.type.ts | 0 .../{ => route}/source/create-path-catalog.test.ts | 6 +++--- src/routing/{ => route}/source/create-path-catalog.ts | 4 ++-- .../{ => route}/source/normalize-route-sources.test.ts | 4 ++-- .../{ => route}/source/normalize-route-sources.ts | 6 +++--- .../{ => route}/source/resolve-path-template.test.ts | 0 .../{ => route}/source/resolve-path-template.ts | 0 src/routing/{ => route}/source/route-source.ts | 4 ++-- .../validation/validate-route-definitions.test.ts | 0 .../validation/validate-route-definitions.ts | 4 ++-- .../{helpers => verb}/http-verb-helpers.test.ts | 0 src/routing/{helpers => verb}/http-verb-helpers.ts | 4 ++-- 35 files changed, 60 insertions(+), 60 deletions(-) rename src/routing/{helpers => group}/route-group.test.ts (94%) rename src/routing/{helpers => group}/route-group.ts (87%) rename src/routing/{helpers => path}/create-path-for.test.ts (94%) rename src/routing/{helpers => path}/create-path-for.ts (73%) rename src/routing/{ => route}/definition/create-route-definition.test.ts (100%) rename src/routing/{ => route}/definition/create-route-definition.ts (85%) rename src/routing/{ => route}/definition/resolve-route-options.test.ts (100%) rename src/routing/{ => route}/definition/resolve-route-options.ts (92%) rename src/routing/{ => route}/definition/route-definition.ts (85%) rename src/routing/{ => route}/registration/expand-route-definitions.test.ts (100%) rename src/routing/{ => route}/registration/expand-route-definitions.ts (84%) rename src/routing/{ => route}/registration/register-routes.test.ts (96%) rename src/routing/{ => route}/registration/register-routes.ts (76%) rename src/routing/{ => route}/registration/route-registration.ts (72%) rename src/routing/{ => route}/route-options.ts (100%) rename src/routing/{ => route}/route.test.ts (100%) rename src/routing/{ => route}/route.ts (70%) rename src/routing/{ => route}/router-method.type.ts (100%) rename src/routing/{ => route}/source/create-path-catalog.test.ts (93%) rename src/routing/{ => route}/source/create-path-catalog.ts (73%) rename src/routing/{ => route}/source/normalize-route-sources.test.ts (98%) rename src/routing/{ => route}/source/normalize-route-sources.ts (94%) rename src/routing/{ => route}/source/resolve-path-template.test.ts (100%) rename src/routing/{ => route}/source/resolve-path-template.ts (100%) rename src/routing/{ => route}/source/route-source.ts (57%) rename src/routing/{ => route}/validation/validate-route-definitions.test.ts (100%) rename src/routing/{ => route}/validation/validate-route-definitions.ts (86%) rename src/routing/{helpers => verb}/http-verb-helpers.test.ts (100%) rename src/routing/{helpers => verb}/http-verb-helpers.ts (96%) diff --git a/src/application/create-application.ts b/src/application/create-application.ts index fffe043..6a35834 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -6,7 +6,7 @@ import { initializeRequestScopeStorage } from '@/Http/Scope/request-scope-storag import { registerEventSubscribers } from '@/Kernel'; import { registerLegacyRoutes } from '@/routing/deprecated-decorator/legacy-router'; import { verifyRoutingMode } from '@/routing/deprecated-decorator/verify-routing-mode'; -import { registerRoutes } from '@/routing/registration/register-routes'; +import { registerRoutes } from '@/routing/route/registration/register-routes'; import type { Request } from 'koa'; import Koa from 'koa'; import { type Application } from './application'; diff --git a/src/index.ts b/src/index.ts index 50bde39..2b3978f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,8 +14,8 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/verb/http-method.type'; -export type { RouteOptions } from '@/routing/route-options'; -export type { RouterMethod } from '@/routing/router-method.type'; +export type { RouteOptions } from '@/routing/route/route-options'; +export type { RouterMethod } from '@/routing/route/router-method.type'; /** * @deprecated Use `Route` from `@koala-ts/framework/routing` instead. */ diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index bd1d483..fdb7ecc 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,8 +1,8 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; -import { createRouteDefinition } from '@/routing/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import { registerRoutes } from '@/routing/registration/register-routes'; +import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import { registerRoutes } from '@/routing/route/registration/register-routes'; import 'reflect-metadata'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; diff --git a/src/routing/deprecated-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts index 42042fc..47aaa6b 100644 --- a/src/routing/deprecated-decorator/route-metadata.ts +++ b/src/routing/deprecated-decorator/route-metadata.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; -import type { RouteOptions } from '@/routing/route-options'; -import type { RouterMethod } from '@/routing/router-method.type'; +import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouterMethod } from '@/routing/route/router-method.type'; /** * @deprecated Legacy decorator routing metadata. Use `@koala-ts/framework/routing` instead. diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index fbc6cbe..6ca2b59 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { RouteOptions } from '@/routing/route-options'; +import type { RouteOptions } from '@/routing/route/route-options'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import { createLegacyRouteDecorator } from './legacy-router'; diff --git a/src/routing/helpers/route-group.test.ts b/src/routing/group/route-group.test.ts similarity index 94% rename from src/routing/helpers/route-group.test.ts rename to src/routing/group/route-group.test.ts index 87e54c6..4b1cdba 100644 --- a/src/routing/helpers/route-group.test.ts +++ b/src/routing/group/route-group.test.ts @@ -1,5 +1,5 @@ +import { Get } from '@/routing/verb/http-verb-helpers'; import { describe, expect, test } from 'vitest'; -import { Get } from '@/routing/helpers/http-verb-helpers'; import { RouteGroup } from './route-group'; describe('route group', () => { diff --git a/src/routing/helpers/route-group.ts b/src/routing/group/route-group.ts similarity index 87% rename from src/routing/helpers/route-group.ts rename to src/routing/group/route-group.ts index a282153..c41d7f9 100644 --- a/src/routing/helpers/route-group.ts +++ b/src/routing/group/route-group.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouteDeclaration } from '@/routing/route'; -import type { RouteSource } from '@/routing/source/route-source'; +import type { RouteDeclaration } from '@/routing/route/route'; +import type { RouteSource } from '@/routing/route/source/route-source'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< diff --git a/src/routing/index.ts b/src/routing/index.ts index ec0b3b4..567a4e3 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,5 +1,5 @@ -export type { RouteSource } from '@/routing/source/route-source'; -export { Route } from './route'; -export { createPathFor } from './helpers/create-path-for'; -export { RouteGroup } from './helpers/route-group'; -export { Any, Delete, Get, Head, Options, Patch, Post, Put } from './helpers/http-verb-helpers'; +export type { RouteSource } from '@/routing/route/source/route-source'; +export { Route } from './route/route'; +export { createPathFor } from './path/create-path-for'; +export { RouteGroup } from './group/route-group'; +export { Any, Delete, Get, Head, Options, Patch, Post, Put } from './verb/http-verb-helpers'; diff --git a/src/routing/helpers/create-path-for.test.ts b/src/routing/path/create-path-for.test.ts similarity index 94% rename from src/routing/helpers/create-path-for.test.ts rename to src/routing/path/create-path-for.test.ts index dbc2f8f..97e5538 100644 --- a/src/routing/helpers/create-path-for.test.ts +++ b/src/routing/path/create-path-for.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test, vi } from 'vitest'; +import { RouteGroup } from '../group/route-group'; +import { Get } from '../verb/http-verb-helpers'; import { createPathFor } from './create-path-for'; -import { Get } from './http-verb-helpers'; -import { RouteGroup } from './route-group'; describe('create path for', () => { describe('path resolution', () => { diff --git a/src/routing/helpers/create-path-for.ts b/src/routing/path/create-path-for.ts similarity index 73% rename from src/routing/helpers/create-path-for.ts rename to src/routing/path/create-path-for.ts index 7d49c72..dcbfeae 100644 --- a/src/routing/helpers/create-path-for.ts +++ b/src/routing/path/create-path-for.ts @@ -1,6 +1,6 @@ -import { createPathCatalog } from '@/routing/source/create-path-catalog'; -import { createPathTemplateResolver } from '@/routing/source/resolve-path-template'; -import type { RouteSource } from '@/routing/source/route-source'; +import { createPathCatalog } from '@/routing/route/source/create-path-catalog'; +import { createPathTemplateResolver } from '@/routing/route/source/resolve-path-template'; +import type { RouteSource } from '@/routing/route/source/route-source'; type PathParamValue = string | number | boolean; type PathParams = Record; diff --git a/src/routing/definition/create-route-definition.test.ts b/src/routing/route/definition/create-route-definition.test.ts similarity index 100% rename from src/routing/definition/create-route-definition.test.ts rename to src/routing/route/definition/create-route-definition.test.ts diff --git a/src/routing/definition/create-route-definition.ts b/src/routing/route/definition/create-route-definition.ts similarity index 85% rename from src/routing/definition/create-route-definition.ts rename to src/routing/route/definition/create-route-definition.ts index 634565d..fd3afa1 100644 --- a/src/routing/definition/create-route-definition.ts +++ b/src/routing/route/definition/create-route-definition.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import { resolveRouteOptions } from '@/routing/definition/resolve-route-options'; -import type { RouteOptions } from '@/routing/route-options'; -import type { RouterMethod } from '@/routing/router-method.type'; +import { resolveRouteOptions } from '@/routing/route/definition/resolve-route-options'; +import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouterMethod } from '@/routing/route/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition'; diff --git a/src/routing/definition/resolve-route-options.test.ts b/src/routing/route/definition/resolve-route-options.test.ts similarity index 100% rename from src/routing/definition/resolve-route-options.test.ts rename to src/routing/route/definition/resolve-route-options.test.ts diff --git a/src/routing/definition/resolve-route-options.ts b/src/routing/route/definition/resolve-route-options.ts similarity index 92% rename from src/routing/definition/resolve-route-options.ts rename to src/routing/route/definition/resolve-route-options.ts index 53d821d..34947e5 100644 --- a/src/routing/definition/resolve-route-options.ts +++ b/src/routing/route/definition/resolve-route-options.ts @@ -1,4 +1,4 @@ -import type { RouteOptions } from '@/routing/route-options'; +import type { RouteOptions } from '@/routing/route/route-options'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition'; diff --git a/src/routing/definition/route-definition.ts b/src/routing/route/definition/route-definition.ts similarity index 85% rename from src/routing/definition/route-definition.ts rename to src/routing/route/definition/route-definition.ts index 5c5a67f..f7b78ec 100644 --- a/src/routing/definition/route-definition.ts +++ b/src/routing/route/definition/route-definition.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouterMethod } from '@/routing/router-method.type'; +import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; import type { KoaBodyMiddlewareOptions } from 'koa-body'; diff --git a/src/routing/registration/expand-route-definitions.test.ts b/src/routing/route/registration/expand-route-definitions.test.ts similarity index 100% rename from src/routing/registration/expand-route-definitions.test.ts rename to src/routing/route/registration/expand-route-definitions.test.ts diff --git a/src/routing/registration/expand-route-definitions.ts b/src/routing/route/registration/expand-route-definitions.ts similarity index 84% rename from src/routing/registration/expand-route-definitions.ts rename to src/routing/route/registration/expand-route-definitions.ts index 2b88d9f..db01581 100644 --- a/src/routing/registration/expand-route-definitions.ts +++ b/src/routing/route/registration/expand-route-definitions.ts @@ -1,7 +1,7 @@ -import { koaBody } from 'koa-body'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteRegistration } from '@/routing/route/registration/route-registration'; import type { Request } from 'koa'; -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouteRegistration } from '@/routing/registration/route-registration'; +import { koaBody } from 'koa-body'; export function expandRouteDefinitions( routes: RouteDefinition[], diff --git a/src/routing/registration/register-routes.test.ts b/src/routing/route/registration/register-routes.test.ts similarity index 96% rename from src/routing/registration/register-routes.test.ts rename to src/routing/route/registration/register-routes.test.ts index 5729922..266e940 100644 --- a/src/routing/registration/register-routes.test.ts +++ b/src/routing/route/registration/register-routes.test.ts @@ -1,11 +1,11 @@ +import { type Application } from '@/application/application'; +import { RouteGroup } from '@/routing/group/route-group'; +import { Route } from '@/routing/route/route'; +import { Get } from '@/routing/verb/http-verb-helpers'; import Koa from 'koa'; import supertest from 'supertest'; import { describe, expect, test } from 'vitest'; -import { type Application } from '@/application/application'; -import { Get } from '@/routing/helpers/http-verb-helpers'; import { registerRoutes } from './register-routes'; -import { RouteGroup } from '@/routing/helpers/route-group'; -import { Route } from '@/routing/route'; describe('register routes', () => { test('it registers a function-first route', async () => { diff --git a/src/routing/registration/register-routes.ts b/src/routing/route/registration/register-routes.ts similarity index 76% rename from src/routing/registration/register-routes.ts rename to src/routing/route/registration/register-routes.ts index 17e8e40..eb65693 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/route/registration/register-routes.ts @@ -1,11 +1,11 @@ import { type Application } from '@/application/application'; import { type HttpScope } from '@/Http'; -import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; -import { normalizeRouteSources } from '@/routing/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/source/route-source'; -import { validateRouteDefinitions } from '@/routing/validation/validate-route-definitions'; -import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; +import { expandRouteDefinitions } from '@/routing/route/registration/expand-route-definitions'; +import { normalizeRouteSources } from '@/routing/route/source/normalize-route-sources'; +import type { RouteSource } from '@/routing/route/source/route-source'; +import { validateRouteDefinitions } from '@/routing/route/validation/validate-route-definitions'; import Router, { type RouterInstance } from '@koa/router'; +import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; export function registerRoutes( app: Application, diff --git a/src/routing/registration/route-registration.ts b/src/routing/route/registration/route-registration.ts similarity index 72% rename from src/routing/registration/route-registration.ts rename to src/routing/route/registration/route-registration.ts index 03e0c7c..79c0a82 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/route/registration/route-registration.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouterMethod } from '@/routing/router-method.type'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; type RouteRegistrationMiddleware = diff --git a/src/routing/route-options.ts b/src/routing/route/route-options.ts similarity index 100% rename from src/routing/route-options.ts rename to src/routing/route/route-options.ts diff --git a/src/routing/route.test.ts b/src/routing/route/route.test.ts similarity index 100% rename from src/routing/route.test.ts rename to src/routing/route/route.test.ts diff --git a/src/routing/route.ts b/src/routing/route/route.ts similarity index 70% rename from src/routing/route.ts rename to src/routing/route/route.ts index 1ea67d2..1f2cd9d 100644 --- a/src/routing/route.ts +++ b/src/routing/route/route.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import { createRouteDefinition } from '@/routing/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouteOptions } from '@/routing/route-options'; +import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteOptions } from '@/routing/route/route-options'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/router-method.type.ts b/src/routing/route/router-method.type.ts similarity index 100% rename from src/routing/router-method.type.ts rename to src/routing/route/router-method.type.ts diff --git a/src/routing/source/create-path-catalog.test.ts b/src/routing/route/source/create-path-catalog.test.ts similarity index 93% rename from src/routing/source/create-path-catalog.test.ts rename to src/routing/route/source/create-path-catalog.test.ts index 7aed663..f19d405 100644 --- a/src/routing/source/create-path-catalog.test.ts +++ b/src/routing/route/source/create-path-catalog.test.ts @@ -1,7 +1,7 @@ +import { RouteGroup } from '@/routing/group/route-group'; +import { Route } from '@/routing/route/route'; +import { Get } from '@/routing/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; -import { Get } from '@/routing/helpers/http-verb-helpers'; -import { RouteGroup } from '@/routing/helpers/route-group'; -import { Route } from '@/routing/route'; import { createPathCatalog } from './create-path-catalog'; describe('create path catalog', () => { diff --git a/src/routing/source/create-path-catalog.ts b/src/routing/route/source/create-path-catalog.ts similarity index 73% rename from src/routing/source/create-path-catalog.ts rename to src/routing/route/source/create-path-catalog.ts index fd3d1e0..2241d18 100644 --- a/src/routing/source/create-path-catalog.ts +++ b/src/routing/route/source/create-path-catalog.ts @@ -1,5 +1,5 @@ -import { normalizeRouteSources } from '@/routing/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/source/route-source'; +import { normalizeRouteSources } from '@/routing/route/source/normalize-route-sources'; +import type { RouteSource } from '@/routing/route/source/route-source'; export function createPathCatalog(routeSources: RouteSource[]): Map { const catalog = new Map(); diff --git a/src/routing/source/normalize-route-sources.test.ts b/src/routing/route/source/normalize-route-sources.test.ts similarity index 98% rename from src/routing/source/normalize-route-sources.test.ts rename to src/routing/route/source/normalize-route-sources.test.ts index 7d97393..4c54484 100644 --- a/src/routing/source/normalize-route-sources.test.ts +++ b/src/routing/route/source/normalize-route-sources.test.ts @@ -1,6 +1,6 @@ +import { RouteGroup } from '@/routing/group/route-group'; +import { Get } from '@/routing/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; -import { Get } from '@/routing/helpers/http-verb-helpers'; -import { RouteGroup } from '@/routing/helpers/route-group'; import { normalizeRouteSources } from './normalize-route-sources'; describe('normalize route sources', () => { diff --git a/src/routing/source/normalize-route-sources.ts b/src/routing/route/source/normalize-route-sources.ts similarity index 94% rename from src/routing/source/normalize-route-sources.ts rename to src/routing/route/source/normalize-route-sources.ts index 616a25c..34cc828 100644 --- a/src/routing/source/normalize-route-sources.ts +++ b/src/routing/route/source/normalize-route-sources.ts @@ -1,6 +1,6 @@ -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import { mergeRouteOptions } from '@/routing/definition/resolve-route-options'; -import type { RouteGroupDefinition } from '@/routing/helpers/route-group'; +import type { RouteGroupDefinition } from '@/routing/group/route-group'; +import { mergeRouteOptions } from '@/routing/route/definition/resolve-route-options'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/source/resolve-path-template.test.ts b/src/routing/route/source/resolve-path-template.test.ts similarity index 100% rename from src/routing/source/resolve-path-template.test.ts rename to src/routing/route/source/resolve-path-template.test.ts diff --git a/src/routing/source/resolve-path-template.ts b/src/routing/route/source/resolve-path-template.ts similarity index 100% rename from src/routing/source/resolve-path-template.ts rename to src/routing/route/source/resolve-path-template.ts diff --git a/src/routing/source/route-source.ts b/src/routing/route/source/route-source.ts similarity index 57% rename from src/routing/source/route-source.ts rename to src/routing/route/source/route-source.ts index 4e805e7..47f632c 100644 --- a/src/routing/source/route-source.ts +++ b/src/routing/route/source/route-source.ts @@ -1,6 +1,6 @@ -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouteGroupDefinition } from '@/routing/helpers/route-group'; import type { HttpRequest } from '@/Http'; +import type { RouteGroupDefinition } from '@/routing/group/route-group'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; import type { Request } from 'koa'; export type RouteSource = diff --git a/src/routing/validation/validate-route-definitions.test.ts b/src/routing/route/validation/validate-route-definitions.test.ts similarity index 100% rename from src/routing/validation/validate-route-definitions.test.ts rename to src/routing/route/validation/validate-route-definitions.test.ts diff --git a/src/routing/validation/validate-route-definitions.ts b/src/routing/route/validation/validate-route-definitions.ts similarity index 86% rename from src/routing/validation/validate-route-definitions.ts rename to src/routing/route/validation/validate-route-definitions.ts index a4f4fb4..5e55426 100644 --- a/src/routing/validation/validate-route-definitions.ts +++ b/src/routing/route/validation/validate-route-definitions.ts @@ -1,5 +1,5 @@ -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import type { RouteRegistration } from '@/routing/registration/route-registration'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteRegistration } from '@/routing/route/registration/route-registration'; import type { Request } from 'koa'; export function validateRouteDefinitions( diff --git a/src/routing/helpers/http-verb-helpers.test.ts b/src/routing/verb/http-verb-helpers.test.ts similarity index 100% rename from src/routing/helpers/http-verb-helpers.test.ts rename to src/routing/verb/http-verb-helpers.test.ts diff --git a/src/routing/helpers/http-verb-helpers.ts b/src/routing/verb/http-verb-helpers.ts similarity index 96% rename from src/routing/helpers/http-verb-helpers.ts rename to src/routing/verb/http-verb-helpers.ts index 222f209..3080f17 100644 --- a/src/routing/helpers/http-verb-helpers.ts +++ b/src/routing/verb/http-verb-helpers.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/definition/route-definition'; -import { Route } from '@/routing/route'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import { Route } from '@/routing/route/route'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; From 2b67344972dcfbdec63d23202c9fe069d9225f11 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:31:37 +0200 Subject: [PATCH 12/45] wip: fill testing gap --- src/routing/route/route.test.ts | 70 +++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/src/routing/route/route.test.ts b/src/routing/route/route.test.ts index 066a4ee..be31e95 100644 --- a/src/routing/route/route.test.ts +++ b/src/routing/route/route.test.ts @@ -2,35 +2,79 @@ import { describe, expect, test, vi } from 'vitest'; import { Route } from './route'; describe('routing route', () => { - test('it creates a function first route definition', () => { + test('it creates a route definition for a single method', () => { const handler = vi.fn(async () => undefined); - const route = Route({ - method: 'GET', - path: '/users', - handler, - }); + const route = Route({ method: 'GET', path: '/users', handler }); expect(route).toEqual({ - bodyOptions: {}, - handler, + path: '/users', methods: ['get'], + handler, middleware: [], parseBody: true, - path: '/users', + bodyOptions: {}, }); }); - test('it keeps the route name when provided', () => { + test('it creates a route definition with name middleware and body options', () => { const handler = vi.fn(async () => undefined); + const middleware = [vi.fn(async () => undefined)]; const route = Route({ - name: 'users.list', - method: 'GET', + name: 'users.create', + method: 'POST', + path: '/users', + handler, + middleware, + options: { + multipart: true, + parseBody: false, + }, + }); + + expect(route).toEqual({ + name: 'users.create', path: '/users', + methods: ['post'], handler, + middleware, + parseBody: false, + bodyOptions: { + multipart: true, + }, }); + }); + + test('it qualifies multiple methods', () => { + const handler = vi.fn(async () => undefined); + + const route = Route({ method: ['GET', 'POST'], path: '/users', handler }); + + expect(route.methods).toEqual(['get', 'post']); + }); + + test('it normalizes any and all to all', () => { + const handler = vi.fn(async () => undefined); + + const route = Route({ method: ['ANY', 'ALL'], path: '/users', handler }); + + expect(route.methods).toEqual(['all']); + }); + + test('it normalizes any with specific methods to all', () => { + const handler = vi.fn(async () => undefined); + + const route = Route({ method: ['ANY', 'GET'], path: '/users', handler }); + + expect(route.methods).toEqual(['all']); + }); + + test('it removes duplicate specific methods case insensitively', () => { + const handler = vi.fn(async () => undefined); + + const route = Route({ method: ['GET', 'get', 'POST'], path: '/users', handler }); - expect(route.name).toBe('users.list'); + expect(route.methods).toEqual(['get', 'post']); }); }); From efa14333732b8e699ad62b35c469dde7abec71b0 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:33:17 +0200 Subject: [PATCH 13/45] wip: rename type --- .../deprecated-decorator/legacy-router.ts | 2 +- .../create-route-definition.test.ts | 100 ------------------ .../definition/create-route-definition.ts | 2 +- .../route/definition/resolve-route-options.ts | 2 +- ...definition.ts => route-definition.type.ts} | 0 .../registration/expand-route-definitions.ts | 2 +- .../route/registration/route-registration.ts | 2 +- src/routing/route/route.ts | 2 +- .../route/source/normalize-route-sources.ts | 2 +- src/routing/route/source/route-source.ts | 2 +- .../validation/validate-route-definitions.ts | 2 +- src/routing/verb/http-verb-helpers.ts | 2 +- 12 files changed, 10 insertions(+), 110 deletions(-) delete mode 100644 src/routing/route/definition/create-route-definition.test.ts rename src/routing/route/definition/{route-definition.ts => route-definition.type.ts} (100%) diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index fdb7ecc..74f97ba 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,7 +1,7 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import { registerRoutes } from '@/routing/route/registration/register-routes'; import 'reflect-metadata'; import type { Route } from './route'; diff --git a/src/routing/route/definition/create-route-definition.test.ts b/src/routing/route/definition/create-route-definition.test.ts deleted file mode 100644 index fdd8ffd..0000000 --- a/src/routing/route/definition/create-route-definition.test.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { describe, expect, test, vi } from 'vitest'; -import { createRouteDefinition } from './create-route-definition'; - -describe('create route definition', () => { - test('it creates a route definition for a single method', () => { - const handler = vi.fn(async () => undefined); - - const route = createRouteDefinition({ - method: 'GET', - path: '/users', - handler, - }); - - expect(route).toEqual({ - path: '/users', - methods: ['get'], - handler, - middleware: [], - parseBody: true, - bodyOptions: {}, - }); - }); - - test('it creates a route definition with name middleware and body options', () => { - const handler = vi.fn(async () => undefined); - const middleware = [vi.fn(async () => undefined)]; - - const route = createRouteDefinition({ - name: 'users.create', - method: 'POST', - path: '/users', - handler, - middleware, - options: { - multipart: true, - parseBody: false, - }, - }); - - expect(route).toEqual({ - name: 'users.create', - path: '/users', - methods: ['post'], - handler, - middleware, - parseBody: false, - bodyOptions: { - multipart: true, - }, - }); - }); - - test('it qualifies multiple methods', () => { - const handler = vi.fn(async () => undefined); - - const route = createRouteDefinition({ - method: ['GET', 'POST'], - path: '/users', - handler, - }); - - expect(route.methods).toEqual(['get', 'post']); - }); - - test('it normalizes any and all to all', () => { - const handler = vi.fn(async () => undefined); - - const route = createRouteDefinition({ - method: ['ANY', 'ALL'], - path: '/users', - handler, - }); - - expect(route.methods).toEqual(['all']); - }); - - test('it normalizes any with specific methods to all', () => { - const handler = vi.fn(async () => undefined); - - const route = createRouteDefinition({ - method: ['ANY', 'GET'], - path: '/users', - handler, - }); - - expect(route.methods).toEqual(['all']); - }); - - test('it removes duplicate specific methods case-insensitively', () => { - const handler = vi.fn(async () => undefined); - - const route = createRouteDefinition({ - method: ['GET', 'get', 'POST'], - path: '/users', - handler, - }); - - expect(route.methods).toEqual(['get', 'post']); - }); -}); diff --git a/src/routing/route/definition/create-route-definition.ts b/src/routing/route/definition/create-route-definition.ts index fd3afa1..11d81b7 100644 --- a/src/routing/route/definition/create-route-definition.ts +++ b/src/routing/route/definition/create-route-definition.ts @@ -4,7 +4,7 @@ import type { RouteOptions } from '@/routing/route/route-options'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition'; +import type { RouteDefinition } from './route-definition.type'; interface RouteDefinitionInput { name?: string; diff --git a/src/routing/route/definition/resolve-route-options.ts b/src/routing/route/definition/resolve-route-options.ts index 34947e5..e92bcc7 100644 --- a/src/routing/route/definition/resolve-route-options.ts +++ b/src/routing/route/definition/resolve-route-options.ts @@ -1,6 +1,6 @@ import type { RouteOptions } from '@/routing/route/route-options'; import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition'; +import type { RouteDefinition } from './route-definition.type'; export function resolveRouteOptions(options: RouteOptions): Pick { return { diff --git a/src/routing/route/definition/route-definition.ts b/src/routing/route/definition/route-definition.type.ts similarity index 100% rename from src/routing/route/definition/route-definition.ts rename to src/routing/route/definition/route-definition.type.ts diff --git a/src/routing/route/registration/expand-route-definitions.ts b/src/routing/route/registration/expand-route-definitions.ts index db01581..adb9f87 100644 --- a/src/routing/route/registration/expand-route-definitions.ts +++ b/src/routing/route/registration/expand-route-definitions.ts @@ -1,4 +1,4 @@ -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouteRegistration } from '@/routing/route/registration/route-registration'; import type { Request } from 'koa'; import { koaBody } from 'koa-body'; diff --git a/src/routing/route/registration/route-registration.ts b/src/routing/route/registration/route-registration.ts index 79c0a82..8d86eaa 100644 --- a/src/routing/route/registration/route-registration.ts +++ b/src/routing/route/registration/route-registration.ts @@ -1,5 +1,5 @@ import type { HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index 1f2cd9d..c7f64b7 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouteOptions } from '@/routing/route/route-options'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/route/source/normalize-route-sources.ts b/src/routing/route/source/normalize-route-sources.ts index 34cc828..78b74dd 100644 --- a/src/routing/route/source/normalize-route-sources.ts +++ b/src/routing/route/source/normalize-route-sources.ts @@ -1,6 +1,6 @@ import type { RouteGroupDefinition } from '@/routing/group/route-group'; import { mergeRouteOptions } from '@/routing/route/definition/resolve-route-options'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/route/source/route-source.ts b/src/routing/route/source/route-source.ts index 47f632c..68377f7 100644 --- a/src/routing/route/source/route-source.ts +++ b/src/routing/route/source/route-source.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { Request } from 'koa'; export type RouteSource = diff --git a/src/routing/route/validation/validate-route-definitions.ts b/src/routing/route/validation/validate-route-definitions.ts index 5e55426..c25104e 100644 --- a/src/routing/route/validation/validate-route-definitions.ts +++ b/src/routing/route/validation/validate-route-definitions.ts @@ -1,4 +1,4 @@ -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouteRegistration } from '@/routing/route/registration/route-registration'; import type { Request } from 'koa'; diff --git a/src/routing/verb/http-verb-helpers.ts b/src/routing/verb/http-verb-helpers.ts index 3080f17..a95c1ae 100644 --- a/src/routing/verb/http-verb-helpers.ts +++ b/src/routing/verb/http-verb-helpers.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition'; +import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import { Route } from '@/routing/route/route'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; From 1d9451dc14ed03eac8ffa2706c23a625c16f0882 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:33:58 +0200 Subject: [PATCH 14/45] wip: move type --- src/routing/deprecated-decorator/legacy-router.ts | 2 +- src/routing/route/definition/create-route-definition.ts | 2 +- src/routing/route/definition/resolve-route-options.ts | 2 +- src/routing/route/registration/expand-route-definitions.ts | 2 +- src/routing/route/registration/route-registration.ts | 2 +- src/routing/route/{definition => }/route-definition.type.ts | 0 src/routing/route/route.ts | 2 +- src/routing/route/source/normalize-route-sources.ts | 2 +- src/routing/route/source/route-source.ts | 2 +- src/routing/route/validation/validate-route-definitions.ts | 2 +- src/routing/verb/http-verb-helpers.ts | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) rename src/routing/route/{definition => }/route-definition.type.ts (100%) diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index 74f97ba..1171143 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,9 +1,9 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import { registerRoutes } from '@/routing/route/registration/register-routes'; import 'reflect-metadata'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; diff --git a/src/routing/route/definition/create-route-definition.ts b/src/routing/route/definition/create-route-definition.ts index 11d81b7..7b8b9c7 100644 --- a/src/routing/route/definition/create-route-definition.ts +++ b/src/routing/route/definition/create-route-definition.ts @@ -4,7 +4,7 @@ import type { RouteOptions } from '@/routing/route/route-options'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition.type'; +import type { RouteDefinition } from '../route-definition.type'; interface RouteDefinitionInput { name?: string; diff --git a/src/routing/route/definition/resolve-route-options.ts b/src/routing/route/definition/resolve-route-options.ts index e92bcc7..d49914b 100644 --- a/src/routing/route/definition/resolve-route-options.ts +++ b/src/routing/route/definition/resolve-route-options.ts @@ -1,6 +1,6 @@ import type { RouteOptions } from '@/routing/route/route-options'; import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition.type'; +import type { RouteDefinition } from '../route-definition.type'; export function resolveRouteOptions(options: RouteOptions): Pick { return { diff --git a/src/routing/route/registration/expand-route-definitions.ts b/src/routing/route/registration/expand-route-definitions.ts index adb9f87..57fb7ec 100644 --- a/src/routing/route/registration/expand-route-definitions.ts +++ b/src/routing/route/registration/expand-route-definitions.ts @@ -1,5 +1,5 @@ -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouteRegistration } from '@/routing/route/registration/route-registration'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; import { koaBody } from 'koa-body'; diff --git a/src/routing/route/registration/route-registration.ts b/src/routing/route/registration/route-registration.ts index 8d86eaa..323550f 100644 --- a/src/routing/route/registration/route-registration.ts +++ b/src/routing/route/registration/route-registration.ts @@ -1,5 +1,5 @@ import type { HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/route/definition/route-definition.type.ts b/src/routing/route/route-definition.type.ts similarity index 100% rename from src/routing/route/definition/route-definition.type.ts rename to src/routing/route/route-definition.type.ts diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index c7f64b7..01a4de0 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { RouteOptions } from '@/routing/route/route-options'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/route/source/normalize-route-sources.ts b/src/routing/route/source/normalize-route-sources.ts index 78b74dd..90b62f7 100644 --- a/src/routing/route/source/normalize-route-sources.ts +++ b/src/routing/route/source/normalize-route-sources.ts @@ -1,6 +1,6 @@ import type { RouteGroupDefinition } from '@/routing/group/route-group'; import { mergeRouteOptions } from '@/routing/route/definition/resolve-route-options'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/route/source/route-source.ts b/src/routing/route/source/route-source.ts index 68377f7..99a5b84 100644 --- a/src/routing/route/source/route-source.ts +++ b/src/routing/route/source/route-source.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; export type RouteSource = diff --git a/src/routing/route/validation/validate-route-definitions.ts b/src/routing/route/validation/validate-route-definitions.ts index c25104e..0df6904 100644 --- a/src/routing/route/validation/validate-route-definitions.ts +++ b/src/routing/route/validation/validate-route-definitions.ts @@ -1,5 +1,5 @@ -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import type { RouteRegistration } from '@/routing/route/registration/route-registration'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; export function validateRouteDefinitions( diff --git a/src/routing/verb/http-verb-helpers.ts b/src/routing/verb/http-verb-helpers.ts index a95c1ae..3947d6c 100644 --- a/src/routing/verb/http-verb-helpers.ts +++ b/src/routing/verb/http-verb-helpers.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/route/definition/route-definition.type'; import { Route } from '@/routing/route/route'; +import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; From 99821666ef9c0d53e3f9772f42a70434c9e8b770 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:37:24 +0200 Subject: [PATCH 15/45] wip: reorganize modules --- src/application/create-application.ts | 2 +- src/index.ts | 2 +- src/routing/deprecated-decorator/legacy-router.ts | 4 ++-- src/routing/deprecated-decorator/route-metadata.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/group/route-group.ts | 2 +- src/routing/index.ts | 2 +- src/routing/path/create-path-for.ts | 6 +++--- .../registration/expand-route-definitions.test.ts | 0 .../{route => }/registration/expand-route-definitions.ts | 2 +- .../{route => }/registration/register-routes.test.ts | 0 src/routing/{route => }/registration/register-routes.ts | 8 ++++---- .../{route => }/registration/route-registration.ts | 0 .../source/create-path-catalog.test.ts | 0 .../{route => registration}/source/create-path-catalog.ts | 4 ++-- .../source/normalize-route-sources.test.ts | 0 .../source/normalize-route-sources.ts | 2 +- .../source/resolve-path-template.test.ts | 0 .../source/resolve-path-template.ts | 0 .../{route => registration}/source/route-source.ts | 0 .../validation/validate-route-definitions.test.ts | 0 .../validation/validate-route-definitions.ts | 2 +- .../route/{definition => }/create-route-definition.ts | 6 +++--- .../route/{definition => }/resolve-route-options.test.ts | 0 .../route/{definition => }/resolve-route-options.ts | 4 ++-- .../route/{route-options.ts => route-options.type.ts} | 0 src/routing/route/route.ts | 4 ++-- 27 files changed, 27 insertions(+), 27 deletions(-) rename src/routing/{route => }/registration/expand-route-definitions.test.ts (100%) rename src/routing/{route => }/registration/expand-route-definitions.ts (92%) rename src/routing/{route => }/registration/register-routes.test.ts (100%) rename src/routing/{route => }/registration/register-routes.ts (75%) rename src/routing/{route => }/registration/route-registration.ts (100%) rename src/routing/{route => registration}/source/create-path-catalog.test.ts (100%) rename src/routing/{route => registration}/source/create-path-catalog.ts (71%) rename src/routing/{route => registration}/source/normalize-route-sources.test.ts (100%) rename src/routing/{route => registration}/source/normalize-route-sources.ts (97%) rename src/routing/{route => registration}/source/resolve-path-template.test.ts (100%) rename src/routing/{route => registration}/source/resolve-path-template.ts (100%) rename src/routing/{route => registration}/source/route-source.ts (100%) rename src/routing/{route => registration}/validation/validate-route-definitions.test.ts (100%) rename src/routing/{route => registration}/validation/validate-route-definitions.ts (93%) rename src/routing/route/{definition => }/create-route-definition.ts (89%) rename src/routing/route/{definition => }/resolve-route-options.test.ts (100%) rename src/routing/route/{definition => }/resolve-route-options.ts (92%) rename src/routing/route/{route-options.ts => route-options.type.ts} (100%) diff --git a/src/application/create-application.ts b/src/application/create-application.ts index 6a35834..fffe043 100644 --- a/src/application/create-application.ts +++ b/src/application/create-application.ts @@ -6,7 +6,7 @@ import { initializeRequestScopeStorage } from '@/Http/Scope/request-scope-storag import { registerEventSubscribers } from '@/Kernel'; import { registerLegacyRoutes } from '@/routing/deprecated-decorator/legacy-router'; import { verifyRoutingMode } from '@/routing/deprecated-decorator/verify-routing-mode'; -import { registerRoutes } from '@/routing/route/registration/register-routes'; +import { registerRoutes } from '@/routing/registration/register-routes'; import type { Request } from 'koa'; import Koa from 'koa'; import { type Application } from './application'; diff --git a/src/index.ts b/src/index.ts index 2b3978f..01190f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/verb/http-method.type'; -export type { RouteOptions } from '@/routing/route/route-options'; +export type { RouteOptions } from '@/routing/route/route-options.type'; export type { RouterMethod } from '@/routing/route/router-method.type'; /** * @deprecated Use `Route` from `@koala-ts/framework/routing` instead. diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index 1171143..cdf03e9 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,8 +1,8 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; -import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; -import { registerRoutes } from '@/routing/route/registration/register-routes'; +import { registerRoutes } from '@/routing/registration/register-routes'; import 'reflect-metadata'; +import { createRouteDefinition } from '@/routing/route/create-route-definition'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; diff --git a/src/routing/deprecated-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts index 47aaa6b..cbf9ca5 100644 --- a/src/routing/deprecated-decorator/route-metadata.ts +++ b/src/routing/deprecated-decorator/route-metadata.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; /** diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index 6ca2b59..a30915d 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouteOptions } from '@/routing/route/route-options.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import { createLegacyRouteDecorator } from './legacy-router'; diff --git a/src/routing/group/route-group.ts b/src/routing/group/route-group.ts index c41d7f9..ee6dbb3 100644 --- a/src/routing/group/route-group.ts +++ b/src/routing/group/route-group.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { RouteSource } from '@/routing/registration/source/route-source'; import type { RouteDeclaration } from '@/routing/route/route'; -import type { RouteSource } from '@/routing/route/source/route-source'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< diff --git a/src/routing/index.ts b/src/routing/index.ts index 567a4e3..64c4c83 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,4 +1,4 @@ -export type { RouteSource } from '@/routing/route/source/route-source'; +export type { RouteSource } from '@/routing/registration/source/route-source'; export { Route } from './route/route'; export { createPathFor } from './path/create-path-for'; export { RouteGroup } from './group/route-group'; diff --git a/src/routing/path/create-path-for.ts b/src/routing/path/create-path-for.ts index dcbfeae..2b0d53d 100644 --- a/src/routing/path/create-path-for.ts +++ b/src/routing/path/create-path-for.ts @@ -1,6 +1,6 @@ -import { createPathCatalog } from '@/routing/route/source/create-path-catalog'; -import { createPathTemplateResolver } from '@/routing/route/source/resolve-path-template'; -import type { RouteSource } from '@/routing/route/source/route-source'; +import { createPathCatalog } from '@/routing/registration/source/create-path-catalog'; +import { createPathTemplateResolver } from '@/routing/registration/source/resolve-path-template'; +import type { RouteSource } from '@/routing/registration/source/route-source'; type PathParamValue = string | number | boolean; type PathParams = Record; diff --git a/src/routing/route/registration/expand-route-definitions.test.ts b/src/routing/registration/expand-route-definitions.test.ts similarity index 100% rename from src/routing/route/registration/expand-route-definitions.test.ts rename to src/routing/registration/expand-route-definitions.test.ts diff --git a/src/routing/route/registration/expand-route-definitions.ts b/src/routing/registration/expand-route-definitions.ts similarity index 92% rename from src/routing/route/registration/expand-route-definitions.ts rename to src/routing/registration/expand-route-definitions.ts index 57fb7ec..e4256ed 100644 --- a/src/routing/route/registration/expand-route-definitions.ts +++ b/src/routing/registration/expand-route-definitions.ts @@ -1,4 +1,4 @@ -import type { RouteRegistration } from '@/routing/route/registration/route-registration'; +import type { RouteRegistration } from '@/routing/registration/route-registration'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; import { koaBody } from 'koa-body'; diff --git a/src/routing/route/registration/register-routes.test.ts b/src/routing/registration/register-routes.test.ts similarity index 100% rename from src/routing/route/registration/register-routes.test.ts rename to src/routing/registration/register-routes.test.ts diff --git a/src/routing/route/registration/register-routes.ts b/src/routing/registration/register-routes.ts similarity index 75% rename from src/routing/route/registration/register-routes.ts rename to src/routing/registration/register-routes.ts index eb65693..07f0610 100644 --- a/src/routing/route/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -1,9 +1,9 @@ import { type Application } from '@/application/application'; import { type HttpScope } from '@/Http'; -import { expandRouteDefinitions } from '@/routing/route/registration/expand-route-definitions'; -import { normalizeRouteSources } from '@/routing/route/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/route/source/route-source'; -import { validateRouteDefinitions } from '@/routing/route/validation/validate-route-definitions'; +import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; +import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; +import type { RouteSource } from '@/routing/registration/source/route-source'; +import { validateRouteDefinitions } from '@/routing/registration/validation/validate-route-definitions'; import Router, { type RouterInstance } from '@koa/router'; import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; diff --git a/src/routing/route/registration/route-registration.ts b/src/routing/registration/route-registration.ts similarity index 100% rename from src/routing/route/registration/route-registration.ts rename to src/routing/registration/route-registration.ts diff --git a/src/routing/route/source/create-path-catalog.test.ts b/src/routing/registration/source/create-path-catalog.test.ts similarity index 100% rename from src/routing/route/source/create-path-catalog.test.ts rename to src/routing/registration/source/create-path-catalog.test.ts diff --git a/src/routing/route/source/create-path-catalog.ts b/src/routing/registration/source/create-path-catalog.ts similarity index 71% rename from src/routing/route/source/create-path-catalog.ts rename to src/routing/registration/source/create-path-catalog.ts index 2241d18..9eed6b3 100644 --- a/src/routing/route/source/create-path-catalog.ts +++ b/src/routing/registration/source/create-path-catalog.ts @@ -1,5 +1,5 @@ -import { normalizeRouteSources } from '@/routing/route/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/route/source/route-source'; +import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; +import type { RouteSource } from '@/routing/registration/source/route-source'; export function createPathCatalog(routeSources: RouteSource[]): Map { const catalog = new Map(); diff --git a/src/routing/route/source/normalize-route-sources.test.ts b/src/routing/registration/source/normalize-route-sources.test.ts similarity index 100% rename from src/routing/route/source/normalize-route-sources.test.ts rename to src/routing/registration/source/normalize-route-sources.test.ts diff --git a/src/routing/route/source/normalize-route-sources.ts b/src/routing/registration/source/normalize-route-sources.ts similarity index 97% rename from src/routing/route/source/normalize-route-sources.ts rename to src/routing/registration/source/normalize-route-sources.ts index 90b62f7..3b3d941 100644 --- a/src/routing/route/source/normalize-route-sources.ts +++ b/src/routing/registration/source/normalize-route-sources.ts @@ -1,5 +1,5 @@ import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import { mergeRouteOptions } from '@/routing/route/definition/resolve-route-options'; +import { mergeRouteOptions } from '@/routing/route/resolve-route-options'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/route/source/resolve-path-template.test.ts b/src/routing/registration/source/resolve-path-template.test.ts similarity index 100% rename from src/routing/route/source/resolve-path-template.test.ts rename to src/routing/registration/source/resolve-path-template.test.ts diff --git a/src/routing/route/source/resolve-path-template.ts b/src/routing/registration/source/resolve-path-template.ts similarity index 100% rename from src/routing/route/source/resolve-path-template.ts rename to src/routing/registration/source/resolve-path-template.ts diff --git a/src/routing/route/source/route-source.ts b/src/routing/registration/source/route-source.ts similarity index 100% rename from src/routing/route/source/route-source.ts rename to src/routing/registration/source/route-source.ts diff --git a/src/routing/route/validation/validate-route-definitions.test.ts b/src/routing/registration/validation/validate-route-definitions.test.ts similarity index 100% rename from src/routing/route/validation/validate-route-definitions.test.ts rename to src/routing/registration/validation/validate-route-definitions.test.ts diff --git a/src/routing/route/validation/validate-route-definitions.ts b/src/routing/registration/validation/validate-route-definitions.ts similarity index 93% rename from src/routing/route/validation/validate-route-definitions.ts rename to src/routing/registration/validation/validate-route-definitions.ts index 0df6904..89ba518 100644 --- a/src/routing/route/validation/validate-route-definitions.ts +++ b/src/routing/registration/validation/validate-route-definitions.ts @@ -1,4 +1,4 @@ -import type { RouteRegistration } from '@/routing/route/registration/route-registration'; +import type { RouteRegistration } from '@/routing/registration/route-registration'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; diff --git a/src/routing/route/definition/create-route-definition.ts b/src/routing/route/create-route-definition.ts similarity index 89% rename from src/routing/route/definition/create-route-definition.ts rename to src/routing/route/create-route-definition.ts index 7b8b9c7..108769b 100644 --- a/src/routing/route/definition/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -1,10 +1,10 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import { resolveRouteOptions } from '@/routing/route/definition/resolve-route-options'; -import type { RouteOptions } from '@/routing/route/route-options'; +import { resolveRouteOptions } from '@/routing/route/resolve-route-options'; +import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from '../route-definition.type'; +import type { RouteDefinition } from './route-definition.type'; interface RouteDefinitionInput { name?: string; diff --git a/src/routing/route/definition/resolve-route-options.test.ts b/src/routing/route/resolve-route-options.test.ts similarity index 100% rename from src/routing/route/definition/resolve-route-options.test.ts rename to src/routing/route/resolve-route-options.test.ts diff --git a/src/routing/route/definition/resolve-route-options.ts b/src/routing/route/resolve-route-options.ts similarity index 92% rename from src/routing/route/definition/resolve-route-options.ts rename to src/routing/route/resolve-route-options.ts index d49914b..5650a5d 100644 --- a/src/routing/route/definition/resolve-route-options.ts +++ b/src/routing/route/resolve-route-options.ts @@ -1,6 +1,6 @@ -import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from '../route-definition.type'; +import type { RouteDefinition } from './route-definition.type'; export function resolveRouteOptions(options: RouteOptions): Pick { return { diff --git a/src/routing/route/route-options.ts b/src/routing/route/route-options.type.ts similarity index 100% rename from src/routing/route/route-options.ts rename to src/routing/route/route-options.type.ts diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index 01a4de0..c6624e3 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import { createRouteDefinition } from '@/routing/route/definition/create-route-definition'; +import { createRouteDefinition } from '@/routing/route/create-route-definition'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; -import type { RouteOptions } from '@/routing/route/route-options'; +import type { RouteOptions } from '@/routing/route/route-options.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; From 8dc88456c0e562a7419b67cdb7be813992237d12 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:38:11 +0200 Subject: [PATCH 16/45] wip: extract type --- src/routing/group/route-group.ts | 3 ++- src/routing/route/route-declaration.type.ts | 13 +++++++++++++ src/routing/route/route.ts | 14 ++------------ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 src/routing/route/route-declaration.type.ts diff --git a/src/routing/group/route-group.ts b/src/routing/group/route-group.ts index ee6dbb3..9b43cde 100644 --- a/src/routing/group/route-group.ts +++ b/src/routing/group/route-group.ts @@ -1,6 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import type { RouteSource } from '@/routing/registration/source/route-source'; -import type { RouteDeclaration } from '@/routing/route/route'; + +import { RouteDeclaration } from '@/routing/route/route-declaration.type'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< diff --git a/src/routing/route/route-declaration.type.ts b/src/routing/route/route-declaration.type.ts new file mode 100644 index 0000000..2d6bc73 --- /dev/null +++ b/src/routing/route/route-declaration.type.ts @@ -0,0 +1,13 @@ +import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { HttpMethod } from '@/routing/verb/http-method.type'; +import type { Request } from 'koa'; + +export interface RouteDeclaration { + name?: string; + path: string; + method: HttpMethod | HttpMethod[]; + handler: HttpMiddleware; + middleware?: HttpMiddleware[]; + options?: RouteOptions; +} diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index c6624e3..290a4e5 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,19 +1,9 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpRequest } from '@/Http'; import { createRouteDefinition } from '@/routing/route/create-route-definition'; +import { RouteDeclaration } from '@/routing/route/route-declaration.type'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; -import type { RouteOptions } from '@/routing/route/route-options.type'; -import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; -export interface RouteDeclaration { - name?: string; - path: string; - method: HttpMethod | HttpMethod[]; - handler: HttpMiddleware; - middleware?: HttpMiddleware[]; - options?: RouteOptions; -} - export function Route( route: RouteDeclaration, ): RouteDefinition { From 9f517ee829d1952cce29ebbf27bd1cc49f80ef6b Mon Sep 17 00:00:00 2001 From: Dhemy Date: Wed, 3 Jun 2026 21:41:29 +0200 Subject: [PATCH 17/45] wip: delegate to fp route helper --- src/routing/deprecated-decorator/legacy-router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index cdf03e9..d0307d0 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,8 +1,8 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; +import { Route as createRouteDefinition } from '@/routing'; import { registerRoutes } from '@/routing/registration/register-routes'; import 'reflect-metadata'; -import { createRouteDefinition } from '@/routing/route/create-route-definition'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; From ef4a6fb21ad7b7c7e877e77cfe3152ab966be3ba Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 10:59:32 +0200 Subject: [PATCH 18/45] wip: rename type --- src/routing/route/create-route-definition.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 108769b..3eceb5a 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -6,7 +6,7 @@ import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition.type'; -interface RouteDefinitionInput { +interface RouteProps { name?: string; method: HttpMethod | HttpMethod[]; path: string; @@ -22,7 +22,7 @@ export function createRouteDefinition({ handler, middleware = [], options = {}, -}: RouteDefinitionInput): RouteDefinition { +}: RouteProps): RouteDefinition { const routeOptions = resolveRouteOptions(options); return { From ed39b32b5f5ce873dbd0092cf77cfcf50d062cf9 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:01:21 +0200 Subject: [PATCH 19/45] wip: consolidate create route def --- src/routing/route/create-route-definition.ts | 14 +++++++++++++- src/routing/route/resolve-route-options.test.ts | 3 ++- src/routing/route/resolve-route-options.ts | 14 +------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 3eceb5a..1159aba 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -1,5 +1,4 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import { resolveRouteOptions } from '@/routing/route/resolve-route-options'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { HttpMethod } from '@/routing/verb/http-method.type'; @@ -15,6 +14,19 @@ interface RouteProps { options?: RouteOptions; } +export function resolveRouteOptions(options: RouteOptions): Pick { + return { + parseBody: options.parseBody ?? true, + bodyOptions: extractBodyOptions(options), + }; +} + +export function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { + const { parseBody: _parseBody, ...bodyOptions } = options; + + return bodyOptions as RouteDefinition['bodyOptions']; +} + export function createRouteDefinition({ name, method, diff --git a/src/routing/route/resolve-route-options.test.ts b/src/routing/route/resolve-route-options.test.ts index 9ee967a..34f0343 100644 --- a/src/routing/route/resolve-route-options.test.ts +++ b/src/routing/route/resolve-route-options.test.ts @@ -1,5 +1,6 @@ +import { resolveRouteOptions } from '@/routing/route/create-route-definition'; import { describe, expect, test } from 'vitest'; -import { mergeRouteOptions, resolveRouteOptions } from './resolve-route-options'; +import { mergeRouteOptions } from './resolve-route-options'; describe('resolve route options', () => { test('it resolves route definition options from route options', () => { diff --git a/src/routing/route/resolve-route-options.ts b/src/routing/route/resolve-route-options.ts index 5650a5d..a65cbf5 100644 --- a/src/routing/route/resolve-route-options.ts +++ b/src/routing/route/resolve-route-options.ts @@ -1,14 +1,8 @@ +import { extractBodyOptions } from '@/routing/route/create-route-definition'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition.type'; -export function resolveRouteOptions(options: RouteOptions): Pick { - return { - parseBody: options.parseBody ?? true, - bodyOptions: extractBodyOptions(options), - }; -} - export function mergeRouteOptions( route: RouteDefinition, options: RouteOptions, @@ -21,9 +15,3 @@ export function mergeRouteOptions( }, }; } - -function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { - const { parseBody: _parseBody, ...bodyOptions } = options; - - return bodyOptions as RouteDefinition['bodyOptions']; -} From 22cb013f30515fe38eef54c1e0aad49e3709f3af Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:02:16 +0200 Subject: [PATCH 20/45] wip: remove redundant test --- .../route/resolve-route-options.test.ts | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/routing/route/resolve-route-options.test.ts diff --git a/src/routing/route/resolve-route-options.test.ts b/src/routing/route/resolve-route-options.test.ts deleted file mode 100644 index 34f0343..0000000 --- a/src/routing/route/resolve-route-options.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { resolveRouteOptions } from '@/routing/route/create-route-definition'; -import { describe, expect, test } from 'vitest'; -import { mergeRouteOptions } from './resolve-route-options'; - -describe('resolve route options', () => { - test('it resolves route definition options from route options', () => { - const routeOptions = resolveRouteOptions({ - multipart: true, - parseBody: false, - }); - - expect(routeOptions).toEqual({ - parseBody: false, - bodyOptions: { - multipart: true, - }, - }); - }); - - test('it merges overlay options into an existing route definition', () => { - const routeOptions = mergeRouteOptions( - { - path: '/users', - methods: ['post'], - handler: async () => undefined, - middleware: [], - parseBody: true, - bodyOptions: { - jsonLimit: '1mb', - }, - }, - { - multipart: true, - parseBody: false, - }, - ); - - expect(routeOptions).toEqual({ - parseBody: false, - bodyOptions: { - jsonLimit: '1mb', - multipart: true, - }, - }); - }); - - test('it keeps the current parse body setting when the overlay omits it', () => { - const routeOptions = mergeRouteOptions( - { - path: '/users', - methods: ['post'], - handler: async () => undefined, - middleware: [], - parseBody: false, - bodyOptions: { - jsonLimit: '1mb', - }, - }, - { - multipart: true, - }, - ); - - expect(routeOptions).toEqual({ - parseBody: false, - bodyOptions: { - jsonLimit: '1mb', - multipart: true, - }, - }); - }); -}); From e94a9ec750f73c567000f1c4b7f7f94f8b430ceb Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:03:55 +0200 Subject: [PATCH 21/45] wip: decouple modules --- src/routing/route/create-route-definition.ts | 4 ++-- src/routing/route/resolve-route-options.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 1159aba..e2ec25e 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -14,14 +14,14 @@ interface RouteProps { options?: RouteOptions; } -export function resolveRouteOptions(options: RouteOptions): Pick { +function resolveRouteOptions(options: RouteOptions): Pick { return { parseBody: options.parseBody ?? true, bodyOptions: extractBodyOptions(options), }; } -export function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { +function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; return bodyOptions as RouteDefinition['bodyOptions']; diff --git a/src/routing/route/resolve-route-options.ts b/src/routing/route/resolve-route-options.ts index a65cbf5..f17cc0c 100644 --- a/src/routing/route/resolve-route-options.ts +++ b/src/routing/route/resolve-route-options.ts @@ -1,8 +1,13 @@ -import { extractBodyOptions } from '@/routing/route/create-route-definition'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition.type'; +function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { + const { parseBody: _parseBody, ...bodyOptions } = options; + + return bodyOptions as RouteDefinition['bodyOptions']; +} + export function mergeRouteOptions( route: RouteDefinition, options: RouteOptions, From 11db04e22b5bb5a5f7e25b2da9d8b914c9ff2cd4 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:04:59 +0200 Subject: [PATCH 22/45] wip: consolidate source module --- src/routing/registration/source/normalize-route-sources.ts | 2 +- .../{route => registration/source}/resolve-route-options.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/routing/{route => registration/source}/resolve-route-options.ts (90%) diff --git a/src/routing/registration/source/normalize-route-sources.ts b/src/routing/registration/source/normalize-route-sources.ts index 3b3d941..643abf4 100644 --- a/src/routing/registration/source/normalize-route-sources.ts +++ b/src/routing/registration/source/normalize-route-sources.ts @@ -1,5 +1,5 @@ import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import { mergeRouteOptions } from '@/routing/route/resolve-route-options'; +import { mergeRouteOptions } from '@/routing/registration/source/resolve-route-options'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/route/resolve-route-options.ts b/src/routing/registration/source/resolve-route-options.ts similarity index 90% rename from src/routing/route/resolve-route-options.ts rename to src/routing/registration/source/resolve-route-options.ts index f17cc0c..6293330 100644 --- a/src/routing/route/resolve-route-options.ts +++ b/src/routing/registration/source/resolve-route-options.ts @@ -1,6 +1,6 @@ import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition.type'; +import type { RouteDefinition } from '../../route/route-definition.type'; function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; From 02697967aac8fb0df4850009d89974829a581550 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:11:03 +0200 Subject: [PATCH 23/45] wip: fix data types --- src/routing/route/create-route-definition.ts | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index e2ec25e..2224a25 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -27,22 +27,17 @@ function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions return bodyOptions as RouteDefinition['bodyOptions']; } -export function createRouteDefinition({ - name, - method, - path, - handler, - middleware = [], - options = {}, -}: RouteProps): RouteDefinition { - const routeOptions = resolveRouteOptions(options); +export function createRouteDefinition( + routeProps: RouteProps, +): RouteDefinition { + const routeOptions = resolveRouteOptions(routeProps.options ?? {}); return { - name, - path, - methods: qualifyMethods(method), - handler, - middleware, + name: routeProps.name, + path: routeProps.path, + methods: qualifyMethods(routeProps.method), + handler: routeProps.handler, + middleware: routeProps.middleware ?? [], ...routeOptions, }; } From b3bd12a719972ad24178e5fc8fc30106eae0ad6a Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:13:49 +0200 Subject: [PATCH 24/45] wip: inline call --- src/routing/route/create-route-definition.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 2224a25..ecd1f33 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -30,15 +30,13 @@ function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions export function createRouteDefinition( routeProps: RouteProps, ): RouteDefinition { - const routeOptions = resolveRouteOptions(routeProps.options ?? {}); - return { name: routeProps.name, path: routeProps.path, methods: qualifyMethods(routeProps.method), handler: routeProps.handler, middleware: routeProps.middleware ?? [], - ...routeOptions, + ...resolveRouteOptions(routeProps.options ?? {}), }; } From 1f51797f6b22de5a5a4051f26f31628979846765 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:15:19 +0200 Subject: [PATCH 25/45] wip: reorder --- src/routing/route/create-route-definition.ts | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index ecd1f33..7b3ecd7 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -27,6 +27,17 @@ function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions return bodyOptions as RouteDefinition['bodyOptions']; } +function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { + const methods = Array.isArray(method) ? method : [method]; + const qualifiedMethods: RouterMethod[] = methods.map(method => { + const lower = method.toLowerCase() as RouterMethod; + + return ['any', 'all'].includes(lower) ? 'all' : lower; + }); + + return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; +} + export function createRouteDefinition( routeProps: RouteProps, ): RouteDefinition { @@ -39,14 +50,3 @@ export function createRouteDefinition( ...resolveRouteOptions(routeProps.options ?? {}), }; } - -function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { - const methods = Array.isArray(method) ? method : [method]; - const qualifiedMethods: RouterMethod[] = methods.map(method => { - const lower = method.toLowerCase() as RouterMethod; - - return ['any', 'all'].includes(lower) ? 'all' : lower; - }); - - return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; -} From 5b0368261352b0aadbee8d493992d178d9b5633e Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:16:20 +0200 Subject: [PATCH 26/45] wip: consolidate --- src/index.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/group/route-group.test.ts | 2 +- src/routing/index.ts | 2 +- src/routing/path/create-path-for.test.ts | 2 +- src/routing/registration/register-routes.test.ts | 2 +- src/routing/registration/source/create-path-catalog.test.ts | 2 +- src/routing/registration/source/normalize-route-sources.test.ts | 2 +- src/routing/{ => registration}/verb/http-method.type.ts | 0 src/routing/{ => registration}/verb/http-verb-helpers.test.ts | 0 src/routing/{ => registration}/verb/http-verb-helpers.ts | 2 +- src/routing/route/create-route-definition.ts | 2 +- src/routing/route/route-declaration.type.ts | 2 +- 13 files changed, 11 insertions(+), 11 deletions(-) rename src/routing/{ => registration}/verb/http-method.type.ts (100%) rename src/routing/{ => registration}/verb/http-verb-helpers.test.ts (100%) rename src/routing/{ => registration}/verb/http-verb-helpers.ts (97%) diff --git a/src/index.ts b/src/index.ts index 01190f8..a24c30f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; -export type { HttpMethod } from '@/routing/verb/http-method.type'; +export type { HttpMethod } from '@/routing/registration/verb/http-method.type'; export type { RouteOptions } from '@/routing/route/route-options.type'; export type { RouterMethod } from '@/routing/route/router-method.type'; /** diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index a30915d..9a967cf 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; +import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; -import type { HttpMethod } from '@/routing/verb/http-method.type'; import { createLegacyRouteDecorator } from './legacy-router'; /** diff --git a/src/routing/group/route-group.test.ts b/src/routing/group/route-group.test.ts index 4b1cdba..7183c21 100644 --- a/src/routing/group/route-group.test.ts +++ b/src/routing/group/route-group.test.ts @@ -1,4 +1,4 @@ -import { Get } from '@/routing/verb/http-verb-helpers'; +import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test } from 'vitest'; import { RouteGroup } from './route-group'; diff --git a/src/routing/index.ts b/src/routing/index.ts index 64c4c83..2fcf6e2 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -2,4 +2,4 @@ export type { RouteSource } from '@/routing/registration/source/route-source'; export { Route } from './route/route'; export { createPathFor } from './path/create-path-for'; export { RouteGroup } from './group/route-group'; -export { Any, Delete, Get, Head, Options, Patch, Post, Put } from './verb/http-verb-helpers'; +export { Any, Delete, Get, Head, Options, Patch, Post, Put } from '@/routing/registration/verb/http-verb-helpers'; diff --git a/src/routing/path/create-path-for.test.ts b/src/routing/path/create-path-for.test.ts index 97e5538..1cdd7de 100644 --- a/src/routing/path/create-path-for.test.ts +++ b/src/routing/path/create-path-for.test.ts @@ -1,6 +1,6 @@ +import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { RouteGroup } from '../group/route-group'; -import { Get } from '../verb/http-verb-helpers'; import { createPathFor } from './create-path-for'; describe('create path for', () => { diff --git a/src/routing/registration/register-routes.test.ts b/src/routing/registration/register-routes.test.ts index 266e940..0a568c0 100644 --- a/src/routing/registration/register-routes.test.ts +++ b/src/routing/registration/register-routes.test.ts @@ -1,7 +1,7 @@ import { type Application } from '@/application/application'; import { RouteGroup } from '@/routing/group/route-group'; +import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { Route } from '@/routing/route/route'; -import { Get } from '@/routing/verb/http-verb-helpers'; import Koa from 'koa'; import supertest from 'supertest'; import { describe, expect, test } from 'vitest'; diff --git a/src/routing/registration/source/create-path-catalog.test.ts b/src/routing/registration/source/create-path-catalog.test.ts index f19d405..96817a3 100644 --- a/src/routing/registration/source/create-path-catalog.test.ts +++ b/src/routing/registration/source/create-path-catalog.test.ts @@ -1,6 +1,6 @@ import { RouteGroup } from '@/routing/group/route-group'; +import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { Route } from '@/routing/route/route'; -import { Get } from '@/routing/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { createPathCatalog } from './create-path-catalog'; diff --git a/src/routing/registration/source/normalize-route-sources.test.ts b/src/routing/registration/source/normalize-route-sources.test.ts index 4c54484..c8a3aa4 100644 --- a/src/routing/registration/source/normalize-route-sources.test.ts +++ b/src/routing/registration/source/normalize-route-sources.test.ts @@ -1,5 +1,5 @@ import { RouteGroup } from '@/routing/group/route-group'; -import { Get } from '@/routing/verb/http-verb-helpers'; +import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { normalizeRouteSources } from './normalize-route-sources'; diff --git a/src/routing/verb/http-method.type.ts b/src/routing/registration/verb/http-method.type.ts similarity index 100% rename from src/routing/verb/http-method.type.ts rename to src/routing/registration/verb/http-method.type.ts diff --git a/src/routing/verb/http-verb-helpers.test.ts b/src/routing/registration/verb/http-verb-helpers.test.ts similarity index 100% rename from src/routing/verb/http-verb-helpers.test.ts rename to src/routing/registration/verb/http-verb-helpers.test.ts diff --git a/src/routing/verb/http-verb-helpers.ts b/src/routing/registration/verb/http-verb-helpers.ts similarity index 97% rename from src/routing/verb/http-verb-helpers.ts rename to src/routing/registration/verb/http-verb-helpers.ts index 3947d6c..1126c83 100644 --- a/src/routing/verb/http-verb-helpers.ts +++ b/src/routing/registration/verb/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import { Route } from '@/routing/route/route'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; -import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; type RouteHandler = HttpMiddleware; diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 7b3ecd7..4873c3f 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; -import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition.type'; diff --git a/src/routing/route/route-declaration.type.ts b/src/routing/route/route-declaration.type.ts index 2d6bc73..46769cd 100644 --- a/src/routing/route/route-declaration.type.ts +++ b/src/routing/route/route-declaration.type.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; -import type { HttpMethod } from '@/routing/verb/http-method.type'; import type { Request } from 'koa'; export interface RouteDeclaration { From 8b9a355796fbbab5ffc7b6628bfd22b32f432894 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:23:06 +0200 Subject: [PATCH 27/45] Update create-route-definition.ts --- src/routing/route/create-route-definition.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 4873c3f..6cbbd70 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -5,15 +5,6 @@ import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; import type { RouteDefinition } from './route-definition.type'; -interface RouteProps { - name?: string; - method: HttpMethod | HttpMethod[]; - path: string; - handler: HttpMiddleware; - middleware?: HttpMiddleware[]; - options?: RouteOptions; -} - function resolveRouteOptions(options: RouteOptions): Pick { return { parseBody: options.parseBody ?? true, @@ -38,6 +29,15 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; } +interface RouteProps { + name?: string; + method: HttpMethod | HttpMethod[]; + path: string; + handler: HttpMiddleware; + middleware?: HttpMiddleware[]; + options?: RouteOptions; +} + export function createRouteDefinition( routeProps: RouteProps, ): RouteDefinition { From 827a6e46de8e591cc097606ed65d1edea64af3be Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:26:44 +0200 Subject: [PATCH 28/45] wip: remove unnecessary type --- src/routing/route/create-route-definition.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts index 6cbbd70..243b7b3 100644 --- a/src/routing/route/create-route-definition.ts +++ b/src/routing/route/create-route-definition.ts @@ -1,5 +1,6 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; +import { RouteDeclaration } from '@/routing/route/route-declaration.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; @@ -29,17 +30,8 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; } -interface RouteProps { - name?: string; - method: HttpMethod | HttpMethod[]; - path: string; - handler: HttpMiddleware; - middleware?: HttpMiddleware[]; - options?: RouteOptions; -} - export function createRouteDefinition( - routeProps: RouteProps, + routeProps: RouteDeclaration, ): RouteDefinition { return { name: routeProps.name, From b0d3b5fafcdbebcd13165c46d3402bd064f2a6cf Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:28:36 +0200 Subject: [PATCH 29/45] wip: consolidate into route --- src/routing/route/create-route-definition.ts | 44 -------------------- src/routing/route/route.ts | 41 +++++++++++++++++- 2 files changed, 40 insertions(+), 45 deletions(-) delete mode 100644 src/routing/route/create-route-definition.ts diff --git a/src/routing/route/create-route-definition.ts b/src/routing/route/create-route-definition.ts deleted file mode 100644 index 243b7b3..0000000 --- a/src/routing/route/create-route-definition.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { HttpRequest } from '@/Http'; -import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; -import { RouteDeclaration } from '@/routing/route/route-declaration.type'; -import type { RouteOptions } from '@/routing/route/route-options.type'; -import type { RouterMethod } from '@/routing/route/router-method.type'; -import type { Request } from 'koa'; -import type { RouteDefinition } from './route-definition.type'; - -function resolveRouteOptions(options: RouteOptions): Pick { - return { - parseBody: options.parseBody ?? true, - bodyOptions: extractBodyOptions(options), - }; -} - -function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { - const { parseBody: _parseBody, ...bodyOptions } = options; - - return bodyOptions as RouteDefinition['bodyOptions']; -} - -function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { - const methods = Array.isArray(method) ? method : [method]; - const qualifiedMethods: RouterMethod[] = methods.map(method => { - const lower = method.toLowerCase() as RouterMethod; - - return ['any', 'all'].includes(lower) ? 'all' : lower; - }); - - return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; -} - -export function createRouteDefinition( - routeProps: RouteDeclaration, -): RouteDefinition { - return { - name: routeProps.name, - path: routeProps.path, - methods: qualifyMethods(routeProps.method), - handler: routeProps.handler, - middleware: routeProps.middleware ?? [], - ...resolveRouteOptions(routeProps.options ?? {}), - }; -} diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index 290a4e5..2fc4e09 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,9 +1,48 @@ import type { HttpRequest } from '@/Http'; -import { createRouteDefinition } from '@/routing/route/create-route-definition'; +import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import { RouteDeclaration } from '@/routing/route/route-declaration.type'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; +function resolveRouteOptions(options: RouteOptions): Pick { + return { + parseBody: options.parseBody ?? true, + bodyOptions: extractBodyOptions(options), + }; +} + +function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { + const { parseBody: _parseBody, ...bodyOptions } = options; + + return bodyOptions as RouteDefinition['bodyOptions']; +} + +function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { + const methods = Array.isArray(method) ? method : [method]; + const qualifiedMethods: RouterMethod[] = methods.map(method => { + const lower = method.toLowerCase() as RouterMethod; + + return ['any', 'all'].includes(lower) ? 'all' : lower; + }); + + return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; +} + +export function createRouteDefinition( + routeProps: RouteDeclaration, +): RouteDefinition { + return { + name: routeProps.name, + path: routeProps.path, + methods: qualifyMethods(routeProps.method), + handler: routeProps.handler, + middleware: routeProps.middleware ?? [], + ...resolveRouteOptions(routeProps.options ?? {}), + }; +} + export function Route( route: RouteDeclaration, ): RouteDefinition { From d19d859674c58a687917443730b7d1ea6286e178 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:30:32 +0200 Subject: [PATCH 30/45] wip: move type to root --- src/routing/group/route-group.ts | 4 ++-- .../route-declaration.type.ts => route-props.type.ts} | 2 +- src/routing/route/route.ts | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) rename src/routing/{route/route-declaration.type.ts => route-props.type.ts} (84%) diff --git a/src/routing/group/route-group.ts b/src/routing/group/route-group.ts index 9b43cde..b745f34 100644 --- a/src/routing/group/route-group.ts +++ b/src/routing/group/route-group.ts @@ -1,11 +1,11 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import type { RouteSource } from '@/routing/registration/source/route-source'; -import { RouteDeclaration } from '@/routing/route/route-declaration.type'; +import { RouteProps } from '@/routing/route-props.type'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< - RouteDeclaration, + RouteProps, 'middleware' | 'options' >; diff --git a/src/routing/route/route-declaration.type.ts b/src/routing/route-props.type.ts similarity index 84% rename from src/routing/route/route-declaration.type.ts rename to src/routing/route-props.type.ts index 46769cd..1f88308 100644 --- a/src/routing/route/route-declaration.type.ts +++ b/src/routing/route-props.type.ts @@ -3,7 +3,7 @@ import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; -export interface RouteDeclaration { +export interface RouteProps { name?: string; path: string; method: HttpMethod | HttpMethod[]; diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index 2fc4e09..56413bd 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; -import { RouteDeclaration } from '@/routing/route/route-declaration.type'; +import { RouteProps } from '@/routing/route-props.type'; import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; @@ -31,7 +31,7 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { } export function createRouteDefinition( - routeProps: RouteDeclaration, + routeProps: RouteProps, ): RouteDefinition { return { name: routeProps.name, @@ -43,8 +43,6 @@ export function createRouteDefinition( }; } -export function Route( - route: RouteDeclaration, -): RouteDefinition { +export function Route(route: RouteProps): RouteDefinition { return createRouteDefinition(route); } From 39b79f72d7bb1c3899623828b3eaf008bdd5dd6e Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:31:51 +0200 Subject: [PATCH 31/45] wip: rename internal type --- .../deprecated-decorator/legacy-router.ts | 4 ++-- .../registration/expand-route-definitions.ts | 8 ++++---- src/routing/registration/route-registration.ts | 6 +++--- .../source/normalize-route-sources.ts | 18 +++++++++--------- .../source/resolve-route-options.ts | 10 +++++----- .../registration/source/route-source.ts | 4 ++-- .../validation/validate-route-definitions.ts | 6 +++--- .../registration/verb/http-verb-helpers.ts | 6 +++--- ....type.ts => normalized-route-props.type.ts} | 2 +- src/routing/route/route.ts | 14 ++++++++------ 10 files changed, 40 insertions(+), 38 deletions(-) rename src/routing/route/{route-definition.type.ts => normalized-route-props.type.ts} (84%) diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index d0307d0..7b90e6c 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -3,7 +3,7 @@ import { type HttpMiddleware } from '@/Http'; import { Route as createRouteDefinition } from '@/routing'; import { registerRoutes } from '@/routing/registration/register-routes'; import 'reflect-metadata'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; @@ -23,7 +23,7 @@ export function getLegacyRoutes(): RouteMetadata[] { return (Reflect.getMetadata(legacyRouteMetadataKey, Reflect) ?? []) as RouteMetadata[]; } -export function getLegacyRouteDefinitions(): RouteDefinition[] { +export function getLegacyRouteDefinitions(): NormalizedRouteProps[] { return getLegacyRoutes().map(route => createRouteDefinition({ method: route.methods, diff --git a/src/routing/registration/expand-route-definitions.ts b/src/routing/registration/expand-route-definitions.ts index e4256ed..fc3e3c0 100644 --- a/src/routing/registration/expand-route-definitions.ts +++ b/src/routing/registration/expand-route-definitions.ts @@ -1,10 +1,10 @@ import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; import { koaBody } from 'koa-body'; export function expandRouteDefinitions( - routes: RouteDefinition[], + routes: NormalizedRouteProps[], ): RouteRegistration[] { const registrations: RouteRegistration[] = []; @@ -16,7 +16,7 @@ export function expandRouteDefinitions( } function expandRouteDefinition( - route: RouteDefinition, + route: NormalizedRouteProps, ): RouteRegistration[] { const middleware = resolveRouteMiddleware(route); @@ -28,7 +28,7 @@ function expandRouteDefinition( } function resolveRouteMiddleware( - route: RouteDefinition, + route: NormalizedRouteProps, ): RouteRegistration['middleware'] { const middlewareStack = [...route.middleware, route.handler]; diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index 323550f..ae11379 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,11 +1,11 @@ import type { HttpRequest } from '@/Http'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; type RouteRegistrationMiddleware = - | RouteDefinition['middleware'][number] - | RouteDefinition['handler']; + | NormalizedRouteProps['middleware'][number] + | NormalizedRouteProps['handler']; export interface RouteRegistration { method: RouterMethod; diff --git a/src/routing/registration/source/normalize-route-sources.ts b/src/routing/registration/source/normalize-route-sources.ts index 643abf4..20c8180 100644 --- a/src/routing/registration/source/normalize-route-sources.ts +++ b/src/routing/registration/source/normalize-route-sources.ts @@ -1,13 +1,13 @@ import type { RouteGroupDefinition } from '@/routing/group/route-group'; import { mergeRouteOptions } from '@/routing/registration/source/resolve-route-options'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; interface NormalizationContext { prefix: string; namePrefix: string; - middleware: RouteDefinition['middleware']; + middleware: NormalizedRouteProps['middleware']; } const defaultNormalizationContext = { @@ -19,8 +19,8 @@ const defaultNormalizationContext = { export function normalizeRouteSources( routeSources: RouteSource[], context: NormalizationContext = defaultNormalizationContext, -): RouteDefinition[] { - const routes: RouteDefinition[] = []; +): NormalizedRouteProps[] { + const routes: NormalizedRouteProps[] = []; for (const routeSource of routeSources) { if (isRouteGroupDefinition(routeSource)) { @@ -37,7 +37,7 @@ export function normalizeRouteSources( function normalizeRouteGroup( group: RouteGroupDefinition, parentContext: NormalizationContext, -): RouteDefinition[] { +): NormalizedRouteProps[] { const context = createChildContext(group, parentContext); return normalizeRouteSources(applyRouteConfig(group.resolveRoutes(), group), context); @@ -58,9 +58,9 @@ function createChildContext( } function normalizeRouteDefinition( - route: RouteDefinition, + route: NormalizedRouteProps, context: NormalizationContext, -): RouteDefinition { +): NormalizedRouteProps { return { ...route, path: joinRoutePath(context.prefix, route.path), @@ -93,9 +93,9 @@ function applyRouteConfig( } function resolveRouteConfigOptions( - route: RouteDefinition, + route: NormalizedRouteProps, routeConfig: NonNullable['options']['routeConfig']>[string], -): Partial, 'parseBody' | 'bodyOptions'>> { +): Partial, 'parseBody' | 'bodyOptions'>> { return routeConfig.options ? mergeRouteOptions(route, routeConfig.options) : {}; } diff --git a/src/routing/registration/source/resolve-route-options.ts b/src/routing/registration/source/resolve-route-options.ts index 6293330..5712324 100644 --- a/src/routing/registration/source/resolve-route-options.ts +++ b/src/routing/registration/source/resolve-route-options.ts @@ -1,17 +1,17 @@ import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; -import type { RouteDefinition } from '../../route/route-definition.type'; +import type { NormalizedRouteProps } from '../../route/normalized-route-props.type'; -function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { +function extractBodyOptions(options: RouteOptions): NormalizedRouteProps['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; - return bodyOptions as RouteDefinition['bodyOptions']; + return bodyOptions as NormalizedRouteProps['bodyOptions']; } export function mergeRouteOptions( - route: RouteDefinition, + route: NormalizedRouteProps, options: RouteOptions, -): Pick, 'parseBody' | 'bodyOptions'> { +): Pick, 'parseBody' | 'bodyOptions'> { return { parseBody: options.parseBody ?? route.parseBody, bodyOptions: { diff --git a/src/routing/registration/source/route-source.ts b/src/routing/registration/source/route-source.ts index 99a5b84..a4714fb 100644 --- a/src/routing/registration/source/route-source.ts +++ b/src/routing/registration/source/route-source.ts @@ -1,8 +1,8 @@ import type { HttpRequest } from '@/Http'; import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; export type RouteSource = - | RouteDefinition + | NormalizedRouteProps | RouteGroupDefinition; diff --git a/src/routing/registration/validation/validate-route-definitions.ts b/src/routing/registration/validation/validate-route-definitions.ts index 89ba518..b72f9cb 100644 --- a/src/routing/registration/validation/validate-route-definitions.ts +++ b/src/routing/registration/validation/validate-route-definitions.ts @@ -1,9 +1,9 @@ import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; export function validateRouteDefinitions( - routes: RouteDefinition[], + routes: NormalizedRouteProps[], registrations: RouteRegistration[], ): void { validateUniqueRouteNames(routes); @@ -24,7 +24,7 @@ function validateUniqueRouteSignatures(registrations: } } -function validateUniqueRouteNames(routes: RouteDefinition[]): void { +function validateUniqueRouteNames(routes: NormalizedRouteProps[]): void { const routeNames = new Set(); for (const route of routes) { diff --git a/src/routing/registration/verb/http-verb-helpers.ts b/src/routing/registration/verb/http-verb-helpers.ts index 1126c83..06995c9 100644 --- a/src/routing/registration/verb/http-verb-helpers.ts +++ b/src/routing/registration/verb/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import { Route } from '@/routing/route/route'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; import type { Request } from 'koa'; type RouteHandler = HttpMiddleware; @@ -32,12 +32,12 @@ type NamedVerbHelper = { ( path: string, ...middlewareAndHandler: MiddlewareAndHandler - ): RouteDefinition; + ): NormalizedRouteProps; ( path: string, name: string, ...middlewareAndHandler: MiddlewareAndHandler - ): RouteDefinition; + ): NormalizedRouteProps; }; function createVerbHelper(method: HttpMethod): NamedVerbHelper { diff --git a/src/routing/route/route-definition.type.ts b/src/routing/route/normalized-route-props.type.ts similarity index 84% rename from src/routing/route/route-definition.type.ts rename to src/routing/route/normalized-route-props.type.ts index f7b78ec..e4eeef9 100644 --- a/src/routing/route/route-definition.type.ts +++ b/src/routing/route/normalized-route-props.type.ts @@ -3,7 +3,7 @@ import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; import type { KoaBodyMiddlewareOptions } from 'koa-body'; -export interface RouteDefinition { +export interface NormalizedRouteProps { name?: string; path: string; methods: RouterMethod[]; diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index 56413bd..c69eb84 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,22 +1,22 @@ import type { HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import { RouteProps } from '@/routing/route-props.type'; -import type { RouteDefinition } from '@/routing/route/route-definition.type'; +import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; -function resolveRouteOptions(options: RouteOptions): Pick { +function resolveRouteOptions(options: RouteOptions): Pick { return { parseBody: options.parseBody ?? true, bodyOptions: extractBodyOptions(options), }; } -function extractBodyOptions(options: RouteOptions): RouteDefinition['bodyOptions'] { +function extractBodyOptions(options: RouteOptions): NormalizedRouteProps['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; - return bodyOptions as RouteDefinition['bodyOptions']; + return bodyOptions as NormalizedRouteProps['bodyOptions']; } function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { @@ -32,7 +32,7 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { export function createRouteDefinition( routeProps: RouteProps, -): RouteDefinition { +): NormalizedRouteProps { return { name: routeProps.name, path: routeProps.path, @@ -43,6 +43,8 @@ export function createRouteDefinition( }; } -export function Route(route: RouteProps): RouteDefinition { +export function Route( + route: RouteProps, +): NormalizedRouteProps { return createRouteDefinition(route); } From 527a571244badf0c46073aa3921732672054676e Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:32:30 +0200 Subject: [PATCH 32/45] wip: rename method --- src/routing/route/route.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index c69eb84..a4ae2dc 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -30,7 +30,7 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; } -export function createRouteDefinition( +export function normalizeRouteProps( routeProps: RouteProps, ): NormalizedRouteProps { return { @@ -46,5 +46,5 @@ export function createRouteDefinition( export function Route( route: RouteProps, ): NormalizedRouteProps { - return createRouteDefinition(route); + return normalizeRouteProps(route); } From af8aafa7550872c0e4d3ca388f9b89952d82407d Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:42:01 +0200 Subject: [PATCH 33/45] wip: move route props to declaration --- src/routing/{ => declaration}/route-props.type.ts | 0 src/routing/group/route-group.ts | 4 ++-- src/routing/route/route.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/routing/{ => declaration}/route-props.type.ts (100%) diff --git a/src/routing/route-props.type.ts b/src/routing/declaration/route-props.type.ts similarity index 100% rename from src/routing/route-props.type.ts rename to src/routing/declaration/route-props.type.ts diff --git a/src/routing/group/route-group.ts b/src/routing/group/route-group.ts index b745f34..38df23d 100644 --- a/src/routing/group/route-group.ts +++ b/src/routing/group/route-group.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouteSource } from '@/routing/registration/source/route-source'; -import { RouteProps } from '@/routing/route-props.type'; +import { RouteProps } from '@/routing/declaration/route-props.type'; +import type { RouteSource } from '@/routing/registration/source/route-source'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< diff --git a/src/routing/route/route.ts b/src/routing/route/route.ts index a4ae2dc..6d9b2ea 100644 --- a/src/routing/route/route.ts +++ b/src/routing/route/route.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; +import { RouteProps } from '@/routing/declaration/route-props.type'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; -import { RouteProps } from '@/routing/route-props.type'; import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; From 659a970e9d7b708a532f570aa5c907ca9f76bd93 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:47:40 +0200 Subject: [PATCH 34/45] wip: reogranize into declaration normalization --- .../normalized-route-props.type.ts | 0 .../{group => declaration}/route-group.test.ts | 0 src/routing/{group => declaration}/route-group.ts | 0 src/routing/{route => declaration}/route.test.ts | 0 src/routing/declaration/route.ts | 11 +++++++++++ src/routing/deprecated-decorator/legacy-router.ts | 2 +- src/routing/index.ts | 4 ++-- .../normalize-route-props.ts} | 8 +------- src/routing/path/create-path-for.test.ts | 2 +- src/routing/registration/expand-route-definitions.ts | 2 +- src/routing/registration/register-routes.test.ts | 4 ++-- src/routing/registration/route-registration.ts | 2 +- .../registration/source/create-path-catalog.test.ts | 4 ++-- .../source/normalize-route-sources.test.ts | 2 +- .../registration/source/normalize-route-sources.ts | 4 ++-- .../registration/source/resolve-route-options.ts | 2 +- src/routing/registration/source/route-source.ts | 4 ++-- .../validation/validate-route-definitions.ts | 2 +- src/routing/registration/verb/http-verb-helpers.ts | 4 ++-- 19 files changed, 31 insertions(+), 26 deletions(-) rename src/routing/{route => declaration}/normalized-route-props.type.ts (100%) rename src/routing/{group => declaration}/route-group.test.ts (100%) rename src/routing/{group => declaration}/route-group.ts (100%) rename src/routing/{route => declaration}/route.test.ts (100%) create mode 100644 src/routing/declaration/route.ts rename src/routing/{route/route.ts => normalization/normalize-route-props.ts} (86%) diff --git a/src/routing/route/normalized-route-props.type.ts b/src/routing/declaration/normalized-route-props.type.ts similarity index 100% rename from src/routing/route/normalized-route-props.type.ts rename to src/routing/declaration/normalized-route-props.type.ts diff --git a/src/routing/group/route-group.test.ts b/src/routing/declaration/route-group.test.ts similarity index 100% rename from src/routing/group/route-group.test.ts rename to src/routing/declaration/route-group.test.ts diff --git a/src/routing/group/route-group.ts b/src/routing/declaration/route-group.ts similarity index 100% rename from src/routing/group/route-group.ts rename to src/routing/declaration/route-group.ts diff --git a/src/routing/route/route.test.ts b/src/routing/declaration/route.test.ts similarity index 100% rename from src/routing/route/route.test.ts rename to src/routing/declaration/route.test.ts diff --git a/src/routing/declaration/route.ts b/src/routing/declaration/route.ts new file mode 100644 index 0000000..56b5463 --- /dev/null +++ b/src/routing/declaration/route.ts @@ -0,0 +1,11 @@ +import type { HttpRequest } from '@/Http'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; +import { RouteProps } from '@/routing/declaration/route-props.type'; +import { normalizeRouteProps } from '@/routing/normalization/normalize-route-props'; +import type { Request } from 'koa'; + +export function Route( + route: RouteProps, +): NormalizedRouteProps { + return normalizeRouteProps(route); +} diff --git a/src/routing/deprecated-decorator/legacy-router.ts b/src/routing/deprecated-decorator/legacy-router.ts index 7b90e6c..79937f8 100644 --- a/src/routing/deprecated-decorator/legacy-router.ts +++ b/src/routing/deprecated-decorator/legacy-router.ts @@ -1,9 +1,9 @@ import { type Application } from '@/application/application'; import { type HttpMiddleware } from '@/Http'; import { Route as createRouteDefinition } from '@/routing'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { registerRoutes } from '@/routing/registration/register-routes'; import 'reflect-metadata'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Route } from './route'; import type { RouteMetadata } from './route-metadata'; diff --git a/src/routing/index.ts b/src/routing/index.ts index 2fcf6e2..9a65468 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,5 +1,5 @@ export type { RouteSource } from '@/routing/registration/source/route-source'; -export { Route } from './route/route'; +export { Route } from './declaration/route'; export { createPathFor } from './path/create-path-for'; -export { RouteGroup } from './group/route-group'; +export { RouteGroup } from './declaration/route-group'; export { Any, Delete, Get, Head, Options, Patch, Post, Put } from '@/routing/registration/verb/http-verb-helpers'; diff --git a/src/routing/route/route.ts b/src/routing/normalization/normalize-route-props.ts similarity index 86% rename from src/routing/route/route.ts rename to src/routing/normalization/normalize-route-props.ts index 6d9b2ea..f222e72 100644 --- a/src/routing/route/route.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -1,7 +1,7 @@ import type { HttpRequest } from '@/Http'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; @@ -42,9 +42,3 @@ export function normalizeRouteProps( ...resolveRouteOptions(routeProps.options ?? {}), }; } - -export function Route( - route: RouteProps, -): NormalizedRouteProps { - return normalizeRouteProps(route); -} diff --git a/src/routing/path/create-path-for.test.ts b/src/routing/path/create-path-for.test.ts index 1cdd7de..7a18e73 100644 --- a/src/routing/path/create-path-for.test.ts +++ b/src/routing/path/create-path-for.test.ts @@ -1,6 +1,6 @@ import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; -import { RouteGroup } from '../group/route-group'; +import { RouteGroup } from '../declaration/route-group'; import { createPathFor } from './create-path-for'; describe('create path for', () => { diff --git a/src/routing/registration/expand-route-definitions.ts b/src/routing/registration/expand-route-definitions.ts index fc3e3c0..5286a24 100644 --- a/src/routing/registration/expand-route-definitions.ts +++ b/src/routing/registration/expand-route-definitions.ts @@ -1,5 +1,5 @@ +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; import { koaBody } from 'koa-body'; diff --git a/src/routing/registration/register-routes.test.ts b/src/routing/registration/register-routes.test.ts index 0a568c0..5f25bff 100644 --- a/src/routing/registration/register-routes.test.ts +++ b/src/routing/registration/register-routes.test.ts @@ -1,7 +1,7 @@ import { type Application } from '@/application/application'; -import { RouteGroup } from '@/routing/group/route-group'; +import { Route } from '@/routing/declaration/route'; +import { RouteGroup } from '@/routing/declaration/route-group'; import { Get } from '@/routing/registration/verb/http-verb-helpers'; -import { Route } from '@/routing/route/route'; import Koa from 'koa'; import supertest from 'supertest'; import { describe, expect, test } from 'vitest'; diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index ae11379..76ae2ce 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,5 +1,5 @@ import type { HttpRequest } from '@/Http'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/registration/source/create-path-catalog.test.ts b/src/routing/registration/source/create-path-catalog.test.ts index 96817a3..bcdf285 100644 --- a/src/routing/registration/source/create-path-catalog.test.ts +++ b/src/routing/registration/source/create-path-catalog.test.ts @@ -1,6 +1,6 @@ -import { RouteGroup } from '@/routing/group/route-group'; +import { Route } from '@/routing/declaration/route'; +import { RouteGroup } from '@/routing/declaration/route-group'; import { Get } from '@/routing/registration/verb/http-verb-helpers'; -import { Route } from '@/routing/route/route'; import { describe, expect, test, vi } from 'vitest'; import { createPathCatalog } from './create-path-catalog'; diff --git a/src/routing/registration/source/normalize-route-sources.test.ts b/src/routing/registration/source/normalize-route-sources.test.ts index c8a3aa4..7c573fd 100644 --- a/src/routing/registration/source/normalize-route-sources.test.ts +++ b/src/routing/registration/source/normalize-route-sources.test.ts @@ -1,4 +1,4 @@ -import { RouteGroup } from '@/routing/group/route-group'; +import { RouteGroup } from '@/routing/declaration/route-group'; import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { normalizeRouteSources } from './normalize-route-sources'; diff --git a/src/routing/registration/source/normalize-route-sources.ts b/src/routing/registration/source/normalize-route-sources.ts index 20c8180..ba268e7 100644 --- a/src/routing/registration/source/normalize-route-sources.ts +++ b/src/routing/registration/source/normalize-route-sources.ts @@ -1,6 +1,6 @@ -import type { RouteGroupDefinition } from '@/routing/group/route-group'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; +import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; import { mergeRouteOptions } from '@/routing/registration/source/resolve-route-options'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; import type { RouteSource } from './route-source'; diff --git a/src/routing/registration/source/resolve-route-options.ts b/src/routing/registration/source/resolve-route-options.ts index 5712324..c17d75a 100644 --- a/src/routing/registration/source/resolve-route-options.ts +++ b/src/routing/registration/source/resolve-route-options.ts @@ -1,6 +1,6 @@ import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; -import type { NormalizedRouteProps } from '../../route/normalized-route-props.type'; +import type { NormalizedRouteProps } from '../../declaration/normalized-route-props.type'; function extractBodyOptions(options: RouteOptions): NormalizedRouteProps['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; diff --git a/src/routing/registration/source/route-source.ts b/src/routing/registration/source/route-source.ts index a4714fb..b38a1fb 100644 --- a/src/routing/registration/source/route-source.ts +++ b/src/routing/registration/source/route-source.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; -import type { RouteGroupDefinition } from '@/routing/group/route-group'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; +import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; import type { Request } from 'koa'; export type RouteSource = diff --git a/src/routing/registration/validation/validate-route-definitions.ts b/src/routing/registration/validation/validate-route-definitions.ts index b72f9cb..9b25fa0 100644 --- a/src/routing/registration/validation/validate-route-definitions.ts +++ b/src/routing/registration/validation/validate-route-definitions.ts @@ -1,5 +1,5 @@ +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; import type { Request } from 'koa'; export function validateRouteDefinitions( diff --git a/src/routing/registration/verb/http-verb-helpers.ts b/src/routing/registration/verb/http-verb-helpers.ts index 06995c9..8083933 100644 --- a/src/routing/registration/verb/http-verb-helpers.ts +++ b/src/routing/registration/verb/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; +import { Route } from '@/routing/declaration/route'; import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; -import type { NormalizedRouteProps } from '@/routing/route/normalized-route-props.type'; -import { Route } from '@/routing/route/route'; import type { Request } from 'koa'; type RouteHandler = HttpMiddleware; From f265cca81a4d125ca307fc3a69484e1810c3b425 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:50:58 +0200 Subject: [PATCH 35/45] wip: consolidate --- .../verb => declaration}/http-verb-helpers.test.ts | 0 .../{registration/verb => declaration}/http-verb-helpers.ts | 0 src/routing/declaration/route-group.test.ts | 2 +- src/routing/declaration/route-group.ts | 2 +- .../route-source.ts => declaration/route-source.type.ts} | 0 src/routing/index.ts | 4 ++-- src/routing/path/create-path-for.test.ts | 2 +- src/routing/path/create-path-for.ts | 2 +- src/routing/registration/register-routes.test.ts | 2 +- src/routing/registration/register-routes.ts | 2 +- src/routing/registration/source/create-path-catalog.test.ts | 2 +- src/routing/registration/source/create-path-catalog.ts | 2 +- .../registration/source/normalize-route-sources.test.ts | 2 +- src/routing/registration/source/normalize-route-sources.ts | 2 +- 14 files changed, 12 insertions(+), 12 deletions(-) rename src/routing/{registration/verb => declaration}/http-verb-helpers.test.ts (100%) rename src/routing/{registration/verb => declaration}/http-verb-helpers.ts (100%) rename src/routing/{registration/source/route-source.ts => declaration/route-source.type.ts} (100%) diff --git a/src/routing/registration/verb/http-verb-helpers.test.ts b/src/routing/declaration/http-verb-helpers.test.ts similarity index 100% rename from src/routing/registration/verb/http-verb-helpers.test.ts rename to src/routing/declaration/http-verb-helpers.test.ts diff --git a/src/routing/registration/verb/http-verb-helpers.ts b/src/routing/declaration/http-verb-helpers.ts similarity index 100% rename from src/routing/registration/verb/http-verb-helpers.ts rename to src/routing/declaration/http-verb-helpers.ts diff --git a/src/routing/declaration/route-group.test.ts b/src/routing/declaration/route-group.test.ts index 7183c21..a1a1af0 100644 --- a/src/routing/declaration/route-group.test.ts +++ b/src/routing/declaration/route-group.test.ts @@ -1,4 +1,4 @@ -import { Get } from '@/routing/registration/verb/http-verb-helpers'; +import { Get } from '@/routing/declaration/http-verb-helpers'; import { describe, expect, test } from 'vitest'; import { RouteGroup } from './route-group'; diff --git a/src/routing/declaration/route-group.ts b/src/routing/declaration/route-group.ts index 38df23d..61748d1 100644 --- a/src/routing/declaration/route-group.ts +++ b/src/routing/declaration/route-group.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import { RouteProps } from '@/routing/declaration/route-props.type'; -import type { RouteSource } from '@/routing/registration/source/route-source'; +import type { RouteSource } from '@/routing/declaration/route-source.type'; import type { Request } from 'koa'; export type RouteConfigOverlay = Pick< diff --git a/src/routing/registration/source/route-source.ts b/src/routing/declaration/route-source.type.ts similarity index 100% rename from src/routing/registration/source/route-source.ts rename to src/routing/declaration/route-source.type.ts diff --git a/src/routing/index.ts b/src/routing/index.ts index 9a65468..40b80be 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,5 +1,5 @@ -export type { RouteSource } from '@/routing/registration/source/route-source'; +export type { RouteSource } from '@/routing/declaration/route-source.type'; export { Route } from './declaration/route'; export { createPathFor } from './path/create-path-for'; export { RouteGroup } from './declaration/route-group'; -export { Any, Delete, Get, Head, Options, Patch, Post, Put } from '@/routing/registration/verb/http-verb-helpers'; +export { Any, Delete, Get, Head, Options, Patch, Post, Put } from '@/routing/declaration/http-verb-helpers'; diff --git a/src/routing/path/create-path-for.test.ts b/src/routing/path/create-path-for.test.ts index 7a18e73..a6867cd 100644 --- a/src/routing/path/create-path-for.test.ts +++ b/src/routing/path/create-path-for.test.ts @@ -1,4 +1,4 @@ -import { Get } from '@/routing/registration/verb/http-verb-helpers'; +import { Get } from '@/routing/declaration/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { RouteGroup } from '../declaration/route-group'; import { createPathFor } from './create-path-for'; diff --git a/src/routing/path/create-path-for.ts b/src/routing/path/create-path-for.ts index 2b0d53d..1406bdc 100644 --- a/src/routing/path/create-path-for.ts +++ b/src/routing/path/create-path-for.ts @@ -1,6 +1,6 @@ +import type { RouteSource } from '@/routing/declaration/route-source.type'; import { createPathCatalog } from '@/routing/registration/source/create-path-catalog'; import { createPathTemplateResolver } from '@/routing/registration/source/resolve-path-template'; -import type { RouteSource } from '@/routing/registration/source/route-source'; type PathParamValue = string | number | boolean; type PathParams = Record; diff --git a/src/routing/registration/register-routes.test.ts b/src/routing/registration/register-routes.test.ts index 5f25bff..a84355c 100644 --- a/src/routing/registration/register-routes.test.ts +++ b/src/routing/registration/register-routes.test.ts @@ -1,7 +1,7 @@ import { type Application } from '@/application/application'; +import { Get } from '@/routing/declaration/http-verb-helpers'; import { Route } from '@/routing/declaration/route'; import { RouteGroup } from '@/routing/declaration/route-group'; -import { Get } from '@/routing/registration/verb/http-verb-helpers'; import Koa from 'koa'; import supertest from 'supertest'; import { describe, expect, test } from 'vitest'; diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index 07f0610..1959e66 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -1,8 +1,8 @@ import { type Application } from '@/application/application'; import { type HttpScope } from '@/Http'; +import type { RouteSource } from '@/routing/declaration/route-source.type'; import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/registration/source/route-source'; import { validateRouteDefinitions } from '@/routing/registration/validation/validate-route-definitions'; import Router, { type RouterInstance } from '@koa/router'; import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; diff --git a/src/routing/registration/source/create-path-catalog.test.ts b/src/routing/registration/source/create-path-catalog.test.ts index bcdf285..67752de 100644 --- a/src/routing/registration/source/create-path-catalog.test.ts +++ b/src/routing/registration/source/create-path-catalog.test.ts @@ -1,6 +1,6 @@ +import { Get } from '@/routing/declaration/http-verb-helpers'; import { Route } from '@/routing/declaration/route'; import { RouteGroup } from '@/routing/declaration/route-group'; -import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { createPathCatalog } from './create-path-catalog'; diff --git a/src/routing/registration/source/create-path-catalog.ts b/src/routing/registration/source/create-path-catalog.ts index 9eed6b3..03837ca 100644 --- a/src/routing/registration/source/create-path-catalog.ts +++ b/src/routing/registration/source/create-path-catalog.ts @@ -1,5 +1,5 @@ +import type { RouteSource } from '@/routing/declaration/route-source.type'; import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; -import type { RouteSource } from '@/routing/registration/source/route-source'; export function createPathCatalog(routeSources: RouteSource[]): Map { const catalog = new Map(); diff --git a/src/routing/registration/source/normalize-route-sources.test.ts b/src/routing/registration/source/normalize-route-sources.test.ts index 7c573fd..0fc6145 100644 --- a/src/routing/registration/source/normalize-route-sources.test.ts +++ b/src/routing/registration/source/normalize-route-sources.test.ts @@ -1,5 +1,5 @@ +import { Get } from '@/routing/declaration/http-verb-helpers'; import { RouteGroup } from '@/routing/declaration/route-group'; -import { Get } from '@/routing/registration/verb/http-verb-helpers'; import { describe, expect, test, vi } from 'vitest'; import { normalizeRouteSources } from './normalize-route-sources'; diff --git a/src/routing/registration/source/normalize-route-sources.ts b/src/routing/registration/source/normalize-route-sources.ts index ba268e7..ee26f0a 100644 --- a/src/routing/registration/source/normalize-route-sources.ts +++ b/src/routing/registration/source/normalize-route-sources.ts @@ -2,7 +2,7 @@ import type { NormalizedRouteProps } from '@/routing/declaration/normalized-rout import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; import { mergeRouteOptions } from '@/routing/registration/source/resolve-route-options'; import type { Request } from 'koa'; -import type { RouteSource } from './route-source'; +import type { RouteSource } from '../../declaration/route-source.type'; interface NormalizationContext { prefix: string; From 0f4fb318c09773d12bfb0f6b6d9d32b51640c196 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:52:30 +0200 Subject: [PATCH 36/45] wip: move method type --- src/index.ts | 2 +- .../{registration/verb => declaration}/http-method.type.ts | 0 src/routing/declaration/http-verb-helpers.ts | 2 +- src/routing/declaration/route-props.type.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/normalization/normalize-route-props.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/routing/{registration/verb => declaration}/http-method.type.ts (100%) diff --git a/src/index.ts b/src/index.ts index a24c30f..2773e57 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; -export type { HttpMethod } from '@/routing/registration/verb/http-method.type'; +export type { HttpMethod } from '@/routing/declaration/http-method.type'; export type { RouteOptions } from '@/routing/route/route-options.type'; export type { RouterMethod } from '@/routing/route/router-method.type'; /** diff --git a/src/routing/registration/verb/http-method.type.ts b/src/routing/declaration/http-method.type.ts similarity index 100% rename from src/routing/registration/verb/http-method.type.ts rename to src/routing/declaration/http-method.type.ts diff --git a/src/routing/declaration/http-verb-helpers.ts b/src/routing/declaration/http-verb-helpers.ts index 8083933..ac5b0be 100644 --- a/src/routing/declaration/http-verb-helpers.ts +++ b/src/routing/declaration/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { Route } from '@/routing/declaration/route'; -import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { Request } from 'koa'; type RouteHandler = HttpMiddleware; diff --git a/src/routing/declaration/route-props.type.ts b/src/routing/declaration/route-props.type.ts index 1f88308..f0e36b0 100644 --- a/src/routing/declaration/route-props.type.ts +++ b/src/routing/declaration/route-props.type.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; +import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { Request } from 'koa'; diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index 9a967cf..f21cf5a 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; +import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import { createLegacyRouteDecorator } from './legacy-router'; diff --git a/src/routing/normalization/normalize-route-props.ts b/src/routing/normalization/normalize-route-props.ts index f222e72..e3e4857 100644 --- a/src/routing/normalization/normalize-route-props.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -1,7 +1,7 @@ import type { HttpRequest } from '@/Http'; +import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; -import type { HttpMethod } from '@/routing/registration/verb/http-method.type'; import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; From d0beaa2c63ccdae7aff74fac1e1fc20492171b29 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:54:23 +0200 Subject: [PATCH 37/45] wip: move route options to declaration --- src/routing/{route => declaration}/route-options.type.ts | 0 src/routing/declaration/route-props.type.ts | 2 +- src/routing/deprecated-decorator/route-metadata.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/normalization/normalize-route-props.ts | 2 +- src/routing/registration/source/resolve-route-options.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/routing/{route => declaration}/route-options.type.ts (100%) diff --git a/src/routing/route/route-options.type.ts b/src/routing/declaration/route-options.type.ts similarity index 100% rename from src/routing/route/route-options.type.ts rename to src/routing/declaration/route-options.type.ts diff --git a/src/routing/declaration/route-props.type.ts b/src/routing/declaration/route-props.type.ts index f0e36b0..47a913b 100644 --- a/src/routing/declaration/route-props.type.ts +++ b/src/routing/declaration/route-props.type.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; -import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { RouteOptions } from '@/routing/declaration/route-options.type'; import type { Request } from 'koa'; export interface RouteProps { diff --git a/src/routing/deprecated-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts index cbf9ca5..6ca043c 100644 --- a/src/routing/deprecated-decorator/route-metadata.ts +++ b/src/routing/deprecated-decorator/route-metadata.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware } from '@/Http'; -import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { RouteOptions } from '@/routing/declaration/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; /** diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index f21cf5a..7dda963 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; -import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { RouteOptions } from '@/routing/declaration/route-options.type'; import { createLegacyRouteDecorator } from './legacy-router'; /** diff --git a/src/routing/normalization/normalize-route-props.ts b/src/routing/normalization/normalize-route-props.ts index e3e4857..3fd32ad 100644 --- a/src/routing/normalization/normalize-route-props.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -1,8 +1,8 @@ import type { HttpRequest } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; +import type { RouteOptions } from '@/routing/declaration/route-options.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; -import type { RouteOptions } from '@/routing/route/route-options.type'; import type { RouterMethod } from '@/routing/route/router-method.type'; import type { Request } from 'koa'; diff --git a/src/routing/registration/source/resolve-route-options.ts b/src/routing/registration/source/resolve-route-options.ts index c17d75a..3d204a5 100644 --- a/src/routing/registration/source/resolve-route-options.ts +++ b/src/routing/registration/source/resolve-route-options.ts @@ -1,4 +1,4 @@ -import type { RouteOptions } from '@/routing/route/route-options.type'; +import type { RouteOptions } from '@/routing/declaration/route-options.type'; import type { Request } from 'koa'; import type { NormalizedRouteProps } from '../../declaration/normalized-route-props.type'; From bdf5b6ca773f212d374a984120963fa4370b8966 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:55:34 +0200 Subject: [PATCH 38/45] wip: route method --- src/index.ts | 2 +- src/routing/declaration/normalized-route-props.type.ts | 2 +- src/routing/{route => declaration}/router-method.type.ts | 0 src/routing/deprecated-decorator/route-metadata.ts | 2 +- src/routing/normalization/normalize-route-props.ts | 2 +- src/routing/registration/route-registration.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/routing/{route => declaration}/router-method.type.ts (100%) diff --git a/src/index.ts b/src/index.ts index 2773e57..62f4f24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ export * from '@/Kernel'; export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/declaration/http-method.type'; export type { RouteOptions } from '@/routing/route/route-options.type'; -export type { RouterMethod } from '@/routing/route/router-method.type'; +export type { RouterMethod } from '@/routing/declaration/router-method.type'; /** * @deprecated Use `Route` from `@koala-ts/framework/routing` instead. */ diff --git a/src/routing/declaration/normalized-route-props.type.ts b/src/routing/declaration/normalized-route-props.type.ts index e4eeef9..146ca17 100644 --- a/src/routing/declaration/normalized-route-props.type.ts +++ b/src/routing/declaration/normalized-route-props.type.ts @@ -1,5 +1,5 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; -import type { RouterMethod } from '@/routing/route/router-method.type'; +import type { RouterMethod } from '@/routing/declaration/router-method.type'; import type { Request } from 'koa'; import type { KoaBodyMiddlewareOptions } from 'koa-body'; diff --git a/src/routing/route/router-method.type.ts b/src/routing/declaration/router-method.type.ts similarity index 100% rename from src/routing/route/router-method.type.ts rename to src/routing/declaration/router-method.type.ts diff --git a/src/routing/deprecated-decorator/route-metadata.ts b/src/routing/deprecated-decorator/route-metadata.ts index 6ca043c..cabb213 100644 --- a/src/routing/deprecated-decorator/route-metadata.ts +++ b/src/routing/deprecated-decorator/route-metadata.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; -import type { RouterMethod } from '@/routing/route/router-method.type'; +import type { RouterMethod } from '@/routing/declaration/router-method.type'; /** * @deprecated Legacy decorator routing metadata. Use `@koala-ts/framework/routing` instead. diff --git a/src/routing/normalization/normalize-route-props.ts b/src/routing/normalization/normalize-route-props.ts index 3fd32ad..21de20d 100644 --- a/src/routing/normalization/normalize-route-props.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -3,7 +3,7 @@ import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; -import type { RouterMethod } from '@/routing/route/router-method.type'; +import type { RouterMethod } from '@/routing/declaration/router-method.type'; import type { Request } from 'koa'; function resolveRouteOptions(options: RouteOptions): Pick { diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index 76ae2ce..fb774fc 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; -import type { RouterMethod } from '@/routing/route/router-method.type'; +import type { RouterMethod } from '@/routing/declaration/router-method.type'; import type { Request } from 'koa'; type RouteRegistrationMiddleware = From 3861e790fe66bd66f72de662bdd2cc5676abd2ae Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:57:50 +0200 Subject: [PATCH 39/45] wip: consolidate path --- .../{registration/source => path}/create-path-catalog.test.ts | 0 .../{registration/source => path}/create-path-catalog.ts | 0 src/routing/path/create-path-for.ts | 4 ++-- .../source => path}/resolve-path-template.test.ts | 0 .../{registration/source => path}/resolve-path-template.ts | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename src/routing/{registration/source => path}/create-path-catalog.test.ts (100%) rename src/routing/{registration/source => path}/create-path-catalog.ts (100%) rename src/routing/{registration/source => path}/resolve-path-template.test.ts (100%) rename src/routing/{registration/source => path}/resolve-path-template.ts (100%) diff --git a/src/routing/registration/source/create-path-catalog.test.ts b/src/routing/path/create-path-catalog.test.ts similarity index 100% rename from src/routing/registration/source/create-path-catalog.test.ts rename to src/routing/path/create-path-catalog.test.ts diff --git a/src/routing/registration/source/create-path-catalog.ts b/src/routing/path/create-path-catalog.ts similarity index 100% rename from src/routing/registration/source/create-path-catalog.ts rename to src/routing/path/create-path-catalog.ts diff --git a/src/routing/path/create-path-for.ts b/src/routing/path/create-path-for.ts index 1406bdc..c8f0eb0 100644 --- a/src/routing/path/create-path-for.ts +++ b/src/routing/path/create-path-for.ts @@ -1,6 +1,6 @@ import type { RouteSource } from '@/routing/declaration/route-source.type'; -import { createPathCatalog } from '@/routing/registration/source/create-path-catalog'; -import { createPathTemplateResolver } from '@/routing/registration/source/resolve-path-template'; +import { createPathCatalog } from './create-path-catalog'; +import { createPathTemplateResolver } from './resolve-path-template'; type PathParamValue = string | number | boolean; type PathParams = Record; diff --git a/src/routing/registration/source/resolve-path-template.test.ts b/src/routing/path/resolve-path-template.test.ts similarity index 100% rename from src/routing/registration/source/resolve-path-template.test.ts rename to src/routing/path/resolve-path-template.test.ts diff --git a/src/routing/registration/source/resolve-path-template.ts b/src/routing/path/resolve-path-template.ts similarity index 100% rename from src/routing/registration/source/resolve-path-template.ts rename to src/routing/path/resolve-path-template.ts From 1b722343787b97a72ceaf4d876d4515793058c51 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 11:59:43 +0200 Subject: [PATCH 40/45] wip: move route source to normalization --- .../source => normalization}/normalize-route-sources.test.ts | 0 .../source => normalization}/normalize-route-sources.ts | 2 +- .../source => normalization}/resolve-route-options.ts | 0 src/routing/path/create-path-catalog.ts | 2 +- src/routing/registration/register-routes.ts | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename src/routing/{registration/source => normalization}/normalize-route-sources.test.ts (100%) rename src/routing/{registration/source => normalization}/normalize-route-sources.ts (97%) rename src/routing/{registration/source => normalization}/resolve-route-options.ts (100%) diff --git a/src/routing/registration/source/normalize-route-sources.test.ts b/src/routing/normalization/normalize-route-sources.test.ts similarity index 100% rename from src/routing/registration/source/normalize-route-sources.test.ts rename to src/routing/normalization/normalize-route-sources.test.ts diff --git a/src/routing/registration/source/normalize-route-sources.ts b/src/routing/normalization/normalize-route-sources.ts similarity index 97% rename from src/routing/registration/source/normalize-route-sources.ts rename to src/routing/normalization/normalize-route-sources.ts index ee26f0a..26284c2 100644 --- a/src/routing/registration/source/normalize-route-sources.ts +++ b/src/routing/normalization/normalize-route-sources.ts @@ -1,6 +1,6 @@ import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; -import { mergeRouteOptions } from '@/routing/registration/source/resolve-route-options'; +import { mergeRouteOptions } from '@/routing/normalization/resolve-route-options'; import type { Request } from 'koa'; import type { RouteSource } from '../../declaration/route-source.type'; diff --git a/src/routing/registration/source/resolve-route-options.ts b/src/routing/normalization/resolve-route-options.ts similarity index 100% rename from src/routing/registration/source/resolve-route-options.ts rename to src/routing/normalization/resolve-route-options.ts diff --git a/src/routing/path/create-path-catalog.ts b/src/routing/path/create-path-catalog.ts index 03837ca..c862eb6 100644 --- a/src/routing/path/create-path-catalog.ts +++ b/src/routing/path/create-path-catalog.ts @@ -1,5 +1,5 @@ import type { RouteSource } from '@/routing/declaration/route-source.type'; -import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; +import { normalizeRouteSources } from '@/routing/normalization/normalize-route-sources'; export function createPathCatalog(routeSources: RouteSource[]): Map { const catalog = new Map(); diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index 1959e66..a2c1ebd 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -1,8 +1,8 @@ import { type Application } from '@/application/application'; import { type HttpScope } from '@/Http'; import type { RouteSource } from '@/routing/declaration/route-source.type'; +import { normalizeRouteSources } from '@/routing/normalization/normalize-route-sources'; import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; -import { normalizeRouteSources } from '@/routing/registration/source/normalize-route-sources'; import { validateRouteDefinitions } from '@/routing/registration/validation/validate-route-definitions'; import Router, { type RouterInstance } from '@koa/router'; import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; From ad8f858c24d4a6c560f8e4a58bac4572370ab319 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 12:00:20 +0200 Subject: [PATCH 41/45] wip: flatten registration --- src/routing/registration/register-routes.ts | 2 +- .../{validation => }/validate-route-definitions.test.ts | 0 .../registration/{validation => }/validate-route-definitions.ts | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename src/routing/registration/{validation => }/validate-route-definitions.test.ts (100%) rename src/routing/registration/{validation => }/validate-route-definitions.ts (100%) diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index a2c1ebd..e294ef2 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -3,7 +3,7 @@ import { type HttpScope } from '@/Http'; import type { RouteSource } from '@/routing/declaration/route-source.type'; import { normalizeRouteSources } from '@/routing/normalization/normalize-route-sources'; import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; -import { validateRouteDefinitions } from '@/routing/registration/validation/validate-route-definitions'; +import { validateRouteDefinitions } from '@/routing/registration/validate-route-definitions'; import Router, { type RouterInstance } from '@koa/router'; import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; diff --git a/src/routing/registration/validation/validate-route-definitions.test.ts b/src/routing/registration/validate-route-definitions.test.ts similarity index 100% rename from src/routing/registration/validation/validate-route-definitions.test.ts rename to src/routing/registration/validate-route-definitions.test.ts diff --git a/src/routing/registration/validation/validate-route-definitions.ts b/src/routing/registration/validate-route-definitions.ts similarity index 100% rename from src/routing/registration/validation/validate-route-definitions.ts rename to src/routing/registration/validate-route-definitions.ts From d2c8044c43e4fc72fc8b7a815768ba66d4caac18 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 12:17:53 +0200 Subject: [PATCH 42/45] wip: new names --- ...ions.test.ts => create-route-registrations.test.ts} | 10 +++++----- ...te-definitions.ts => create-route-registrations.ts} | 6 +++--- src/routing/registration/register-routes.ts | 8 ++++---- ...ns.test.ts => validate-route-registrations.test.ts} | 10 +++++----- ...-definitions.ts => validate-route-registrations.ts} | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) rename src/routing/registration/{expand-route-definitions.test.ts => create-route-registrations.test.ts} (79%) rename src/routing/registration/{expand-route-definitions.ts => create-route-registrations.ts} (84%) rename src/routing/registration/{validate-route-definitions.test.ts => validate-route-registrations.test.ts} (92%) rename src/routing/registration/{validate-route-definitions.ts => validate-route-registrations.ts} (94%) diff --git a/src/routing/registration/expand-route-definitions.test.ts b/src/routing/registration/create-route-registrations.test.ts similarity index 79% rename from src/routing/registration/expand-route-definitions.test.ts rename to src/routing/registration/create-route-registrations.test.ts index 63873ae..f0a2dde 100644 --- a/src/routing/registration/expand-route-definitions.test.ts +++ b/src/routing/registration/create-route-registrations.test.ts @@ -1,11 +1,11 @@ import { describe, expect, test, vi } from 'vitest'; -import { expandRouteDefinitions } from './expand-route-definitions'; +import { createRouteRegistrations } from './create-route-registrations'; -describe('expand route definitions', () => { - test('it expands route definitions into route registrations', () => { +describe('create route registrations', () => { + test('it creates route registrations from normalized routes', () => { const handler = vi.fn(async () => undefined); - const registrations = expandRouteDefinitions([ + const registrations = createRouteRegistrations([ { path: '/users', methods: ['get', 'post'], @@ -33,7 +33,7 @@ describe('expand route definitions', () => { test('it prepends koa body middleware when body parsing is enabled', () => { const handler = vi.fn(async () => undefined); - const registrations = expandRouteDefinitions([ + const registrations = createRouteRegistrations([ { path: '/users', methods: ['post'], diff --git a/src/routing/registration/expand-route-definitions.ts b/src/routing/registration/create-route-registrations.ts similarity index 84% rename from src/routing/registration/expand-route-definitions.ts rename to src/routing/registration/create-route-registrations.ts index 5286a24..c5b31a8 100644 --- a/src/routing/registration/expand-route-definitions.ts +++ b/src/routing/registration/create-route-registrations.ts @@ -3,19 +3,19 @@ import type { RouteRegistration } from '@/routing/registration/route-registratio import type { Request } from 'koa'; import { koaBody } from 'koa-body'; -export function expandRouteDefinitions( +export function createRouteRegistrations( routes: NormalizedRouteProps[], ): RouteRegistration[] { const registrations: RouteRegistration[] = []; for (const route of routes) { - registrations.push(...expandRouteDefinition(route)); + registrations.push(...createRouteRegistration(route)); } return registrations; } -function expandRouteDefinition( +function createRouteRegistration( route: NormalizedRouteProps, ): RouteRegistration[] { const middleware = resolveRouteMiddleware(route); diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index e294ef2..da73733 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -2,8 +2,8 @@ import { type Application } from '@/application/application'; import { type HttpScope } from '@/Http'; import type { RouteSource } from '@/routing/declaration/route-source.type'; import { normalizeRouteSources } from '@/routing/normalization/normalize-route-sources'; -import { expandRouteDefinitions } from '@/routing/registration/expand-route-definitions'; -import { validateRouteDefinitions } from '@/routing/registration/validate-route-definitions'; +import { createRouteRegistrations } from '@/routing/registration/create-route-registrations'; +import { validateRouteRegistrations } from '@/routing/registration/validate-route-registrations'; import Router, { type RouterInstance } from '@koa/router'; import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; @@ -22,9 +22,9 @@ export function registerRoutes( function createRouter(routeSources: RouteSource[]): RouterInstance { const router = new Router(); const routes = normalizeRouteSources(routeSources); - const registrations = expandRouteDefinitions(routes); + const registrations = createRouteRegistrations(routes); - validateRouteDefinitions(routes, registrations); + validateRouteRegistrations(routes, registrations); for (const route of registrations) { router[route.method]( diff --git a/src/routing/registration/validate-route-definitions.test.ts b/src/routing/registration/validate-route-registrations.test.ts similarity index 92% rename from src/routing/registration/validate-route-definitions.test.ts rename to src/routing/registration/validate-route-registrations.test.ts index 73c7ac9..980c310 100644 --- a/src/routing/registration/validate-route-definitions.test.ts +++ b/src/routing/registration/validate-route-registrations.test.ts @@ -1,12 +1,12 @@ import { describe, expect, test, vi } from 'vitest'; -import { validateRouteDefinitions } from './validate-route-definitions'; +import { validateRouteRegistrations } from './validate-route-registrations'; -describe('validate route definitions', () => { +describe('validate route registrations', () => { test('it rejects duplicate route signatures', () => { const handler = vi.fn(async () => undefined); expect(() => - validateRouteDefinitions( + validateRouteRegistrations( [ { path: '/users', @@ -45,7 +45,7 @@ describe('validate route definitions', () => { const handler = vi.fn(async () => undefined); expect(() => - validateRouteDefinitions( + validateRouteRegistrations( [ { name: 'users.list', @@ -86,7 +86,7 @@ describe('validate route definitions', () => { const handler = vi.fn(async () => undefined); expect(() => - validateRouteDefinitions( + validateRouteRegistrations( [ { name: 'users.list', diff --git a/src/routing/registration/validate-route-definitions.ts b/src/routing/registration/validate-route-registrations.ts similarity index 94% rename from src/routing/registration/validate-route-definitions.ts rename to src/routing/registration/validate-route-registrations.ts index 9b25fa0..0a7c309 100644 --- a/src/routing/registration/validate-route-definitions.ts +++ b/src/routing/registration/validate-route-registrations.ts @@ -2,7 +2,7 @@ import type { NormalizedRouteProps } from '@/routing/declaration/normalized-rout import type { RouteRegistration } from '@/routing/registration/route-registration'; import type { Request } from 'koa'; -export function validateRouteDefinitions( +export function validateRouteRegistrations( routes: NormalizedRouteProps[], registrations: RouteRegistration[], ): void { From c80375bef0e669eb6994aa8002945b01a60ff82b Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 12:33:05 +0200 Subject: [PATCH 43/45] wip: introduce our type --- src/routing/declaration/normalized-route-props.type.ts | 4 ++-- src/routing/declaration/route-body-options.type.ts | 4 ++++ src/routing/declaration/route-options.type.ts | 4 ++-- src/routing/registration/create-route-registrations.ts | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/routing/declaration/route-body-options.type.ts diff --git a/src/routing/declaration/normalized-route-props.type.ts b/src/routing/declaration/normalized-route-props.type.ts index 146ca17..69d34d1 100644 --- a/src/routing/declaration/normalized-route-props.type.ts +++ b/src/routing/declaration/normalized-route-props.type.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { RouteBodyOptions } from '@/routing/declaration/route-body-options.type'; import type { RouterMethod } from '@/routing/declaration/router-method.type'; import type { Request } from 'koa'; -import type { KoaBodyMiddlewareOptions } from 'koa-body'; export interface NormalizedRouteProps { name?: string; @@ -10,5 +10,5 @@ export interface NormalizedRouteProps { handler: HttpMiddleware; middleware: HttpMiddleware[]; parseBody: boolean; - bodyOptions: Partial; + bodyOptions: RouteBodyOptions; } diff --git a/src/routing/declaration/route-body-options.type.ts b/src/routing/declaration/route-body-options.type.ts new file mode 100644 index 0000000..a0b4edd --- /dev/null +++ b/src/routing/declaration/route-body-options.type.ts @@ -0,0 +1,4 @@ +export interface RouteBodyOptions { + multipart?: boolean; + [option: string]: unknown; +} diff --git a/src/routing/declaration/route-options.type.ts b/src/routing/declaration/route-options.type.ts index d0d7b71..49d9af1 100644 --- a/src/routing/declaration/route-options.type.ts +++ b/src/routing/declaration/route-options.type.ts @@ -1,7 +1,7 @@ -import type { KoaBodyMiddlewareOptions } from 'koa-body'; +import type { RouteBodyOptions } from '@/routing/declaration/route-body-options.type'; export type RouteOptions = Partial< - KoaBodyMiddlewareOptions & { + RouteBodyOptions & { parseBody?: boolean; } >; diff --git a/src/routing/registration/create-route-registrations.ts b/src/routing/registration/create-route-registrations.ts index c5b31a8..8681b91 100644 --- a/src/routing/registration/create-route-registrations.ts +++ b/src/routing/registration/create-route-registrations.ts @@ -32,5 +32,7 @@ function resolveRouteMiddleware( ): RouteRegistration['middleware'] { const middlewareStack = [...route.middleware, route.handler]; - return route.parseBody ? [koaBody(route.bodyOptions), ...middlewareStack] : middlewareStack; + return route.parseBody + ? [koaBody(route.bodyOptions as Parameters[0]), ...middlewareStack] + : middlewareStack; } From 0b897fa77b0c6a7feb52458791b7242f17f4f741 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 12:46:29 +0200 Subject: [PATCH 44/45] wip: introduce our types --- src/Http/Request/types.ts | 3 ++- src/Http/Scope/types.ts | 8 +++--- src/config/koala-config.ts | 5 ++-- src/index.ts | 2 +- src/routing/declaration/http-verb-helpers.ts | 27 +++++++++---------- .../normalized-route-props.type.ts | 5 ++-- src/routing/declaration/route-group.ts | 11 ++++---- src/routing/declaration/route-props.type.ts | 5 ++-- src/routing/declaration/route-source.type.ts | 5 ++-- src/routing/declaration/route.ts | 5 ++-- .../verify-routing-mode.ts | 4 +-- src/routing/index.ts | 2 ++ .../normalization/normalize-route-props.ts | 5 ++-- .../normalization/normalize-route-sources.ts | 20 +++++++------- .../normalization/resolve-route-options.ts | 6 ++--- .../create-route-registrations.ts | 8 +++--- src/routing/registration/register-routes.ts | 8 +++--- .../registration/route-registration.ts | 7 +++-- .../validate-route-registrations.ts | 10 ++++--- 19 files changed, 71 insertions(+), 75 deletions(-) diff --git a/src/Http/Request/types.ts b/src/Http/Request/types.ts index a36c0cd..5eb3d46 100644 --- a/src/Http/Request/types.ts +++ b/src/Http/Request/types.ts @@ -4,8 +4,9 @@ import type { JsonValue } from 'type-fest'; export type UploadedFile = File; export type UploadedFilesMap = Record; +export type HttpRequestBase = Request; -export interface HttpRequest extends Request { +export interface HttpRequest extends HttpRequestBase { body?: Record & JsonValue; files?: UploadedFilesMap; params: Record; diff --git a/src/Http/Scope/types.ts b/src/Http/Scope/types.ts index a7f461a..0008c85 100644 --- a/src/Http/Scope/types.ts +++ b/src/Http/Scope/types.ts @@ -1,9 +1,9 @@ -import type { Context, DefaultState, Next, Request } from 'koa'; -import { type HttpRequest } from '../Request'; +import type { Context, DefaultState, Next } from 'koa'; +import { type HttpRequest, type HttpRequestBase } from '../Request'; import { type HttpResponse } from '../Response'; import { type User } from '@/Security/types'; -export interface HttpScope extends Context { +export interface HttpScope extends Context { request: TRequest; response: HttpResponse; user?: TUser; @@ -11,7 +11,7 @@ export interface HttpScope = ( +export type HttpMiddleware = ( scope: HttpScope, next: NextMiddleware, ) => Promise; diff --git a/src/config/koala-config.ts b/src/config/koala-config.ts index b36329a..9860bfb 100644 --- a/src/config/koala-config.ts +++ b/src/config/koala-config.ts @@ -3,8 +3,7 @@ import { type StaticFilesOptions } from '@/Http/Files'; import { type EventSubscriber } from '@/Kernel'; import type { RouteSource } from '@/routing'; import type { DotenvConfigOptions } from 'dotenv'; -import type { HttpRequest } from '@/Http'; -import type { Request } from 'koa'; +import type { HttpRequest, HttpRequestBase } from '@/Http'; /** * @deprecated Use function-first routes from `@koala-ts/framework/routing` with `KoalaConfig.routes` instead. @@ -13,7 +12,7 @@ export type Controller = new (...args: unknown[]) => unknown; export type KoalaDotenvOptions = Pick; -export interface KoalaConfig { +export interface KoalaConfig { /** * @deprecated Use `routes` with `Route` from `@koala-ts/framework/routing` instead. */ diff --git a/src/index.ts b/src/index.ts index 62f4f24..cadcefd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; export type { HttpMethod } from '@/routing/declaration/http-method.type'; -export type { RouteOptions } from '@/routing/route/route-options.type'; +export type { RouteOptions } from '@/routing/declaration/route-options.type'; export type { RouterMethod } from '@/routing/declaration/router-method.type'; /** * @deprecated Use `Route` from `@koala-ts/framework/routing` instead. diff --git a/src/routing/declaration/http-verb-helpers.ts b/src/routing/declaration/http-verb-helpers.ts index ac5b0be..09fa6a5 100644 --- a/src/routing/declaration/http-verb-helpers.ts +++ b/src/routing/declaration/http-verb-helpers.ts @@ -1,27 +1,26 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { Route } from '@/routing/declaration/route'; -import type { Request } from 'koa'; -type RouteHandler = HttpMiddleware; -type MiddlewareAndHandler = [ +type RouteHandler = HttpMiddleware; +type MiddlewareAndHandler = [ ...middleware: HttpMiddleware[], handler: RouteHandler, ]; -type NamedMiddlewareAndHandler = [ +type NamedMiddlewareAndHandler = [ name: string, ...middlewareAndHandler: MiddlewareAndHandler, ]; -type VerbHelperRouteArguments = +type VerbHelperRouteArguments = | MiddlewareAndHandler | NamedMiddlewareAndHandler; -type UnsafeVerbHelperRouteArguments = +type UnsafeVerbHelperRouteArguments = | VerbHelperRouteArguments | [name: string] | []; -interface VerbHelperArguments { +interface VerbHelperArguments { path: string; name?: string; middleware: HttpMiddleware[]; @@ -29,11 +28,11 @@ interface VerbHelperArguments { } type NamedVerbHelper = { - ( + ( path: string, ...middlewareAndHandler: MiddlewareAndHandler ): NormalizedRouteProps; - ( + ( path: string, name: string, ...middlewareAndHandler: MiddlewareAndHandler @@ -41,7 +40,7 @@ type NamedVerbHelper = { }; function createVerbHelper(method: HttpMethod): NamedVerbHelper { - return ( + return ( path: string, ...routeArguments: UnsafeVerbHelperRouteArguments ) => @@ -51,7 +50,7 @@ function createVerbHelper(method: HttpMethod): NamedVerbHelper { }); } -function resolveVerbHelperArguments( +function resolveVerbHelperArguments( path: string, routeArguments: UnsafeVerbHelperRouteArguments, ): VerbHelperArguments { @@ -71,13 +70,13 @@ function resolveVerbHelperArguments( }; } -function isNamedVerbHelperRouteArguments( +function isNamedVerbHelperRouteArguments( routeArguments: UnsafeVerbHelperRouteArguments, ): routeArguments is NamedMiddlewareAndHandler | [name: string] { return typeof routeArguments[0] === 'string'; } -function requireVerbHelperHandler( +function requireVerbHelperHandler( middlewareAndHandler: MiddlewareAndHandler | [], isNamedRoute: boolean, ): RouteHandler { diff --git a/src/routing/declaration/normalized-route-props.type.ts b/src/routing/declaration/normalized-route-props.type.ts index 69d34d1..0f5234a 100644 --- a/src/routing/declaration/normalized-route-props.type.ts +++ b/src/routing/declaration/normalized-route-props.type.ts @@ -1,9 +1,8 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; import type { RouteBodyOptions } from '@/routing/declaration/route-body-options.type'; import type { RouterMethod } from '@/routing/declaration/router-method.type'; -import type { Request } from 'koa'; -export interface NormalizedRouteProps { +export interface NormalizedRouteProps { name?: string; path: string; methods: RouterMethod[]; diff --git a/src/routing/declaration/route-group.ts b/src/routing/declaration/route-group.ts index 61748d1..0875cd9 100644 --- a/src/routing/declaration/route-group.ts +++ b/src/routing/declaration/route-group.ts @@ -1,28 +1,27 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; import { RouteProps } from '@/routing/declaration/route-props.type'; import type { RouteSource } from '@/routing/declaration/route-source.type'; -import type { Request } from 'koa'; -export type RouteConfigOverlay = Pick< +export type RouteConfigOverlay = Pick< RouteProps, 'middleware' | 'options' >; -export interface RouteGroupOptions { +export interface RouteGroupOptions { prefix?: string; namePrefix?: string; middleware?: HttpMiddleware[]; routeConfig?: Record>; } -export interface RouteGroupDefinition { +export interface RouteGroupDefinition { kind: 'route-group'; options: RouteGroupOptions; resolveRoutes: () => RouteSource[]; } -export function RouteGroup( +export function RouteGroup( options: RouteGroupOptions, resolveRoutes: () => RouteSource[], ): RouteGroupDefinition { diff --git a/src/routing/declaration/route-props.type.ts b/src/routing/declaration/route-props.type.ts index 47a913b..dd0101f 100644 --- a/src/routing/declaration/route-props.type.ts +++ b/src/routing/declaration/route-props.type.ts @@ -1,9 +1,8 @@ -import type { HttpMiddleware, HttpRequest } from '@/Http'; +import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; -import type { Request } from 'koa'; -export interface RouteProps { +export interface RouteProps { name?: string; path: string; method: HttpMethod | HttpMethod[]; diff --git a/src/routing/declaration/route-source.type.ts b/src/routing/declaration/route-source.type.ts index b38a1fb..3462eab 100644 --- a/src/routing/declaration/route-source.type.ts +++ b/src/routing/declaration/route-source.type.ts @@ -1,8 +1,7 @@ -import type { HttpRequest } from '@/Http'; +import type { HttpRequest, HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; -import type { Request } from 'koa'; -export type RouteSource = +export type RouteSource = | NormalizedRouteProps | RouteGroupDefinition; diff --git a/src/routing/declaration/route.ts b/src/routing/declaration/route.ts index 56b5463..6a1bb16 100644 --- a/src/routing/declaration/route.ts +++ b/src/routing/declaration/route.ts @@ -1,10 +1,9 @@ -import type { HttpRequest } from '@/Http'; +import type { HttpRequest, HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; import { normalizeRouteProps } from '@/routing/normalization/normalize-route-props'; -import type { Request } from 'koa'; -export function Route( +export function Route( route: RouteProps, ): NormalizedRouteProps { return normalizeRouteProps(route); diff --git a/src/routing/deprecated-decorator/verify-routing-mode.ts b/src/routing/deprecated-decorator/verify-routing-mode.ts index 993beaf..f1c16a8 100644 --- a/src/routing/deprecated-decorator/verify-routing-mode.ts +++ b/src/routing/deprecated-decorator/verify-routing-mode.ts @@ -1,10 +1,10 @@ import type { KoalaConfig } from '@/config/koala-config'; -import type { Request } from 'koa'; +import type { HttpRequestBase } from '@/Http'; export const exclusiveRoutingModeError = 'Koala routing mode is exclusive. Use either legacy controllers from @koala-ts/framework or routes from @koala-ts/framework/routing.'; -export function verifyRoutingMode(config: KoalaConfig): void { +export function verifyRoutingMode(config: KoalaConfig): void { const controllers = config.controllers ?? []; if (config.routes !== undefined && controllers.length > 0) { diff --git a/src/routing/index.ts b/src/routing/index.ts index 40b80be..bc73de0 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,3 +1,5 @@ +export type { HttpMethod } from '@/routing/declaration/http-method.type'; +export type { RouteOptions } from '@/routing/declaration/route-options.type'; export type { RouteSource } from '@/routing/declaration/route-source.type'; export { Route } from './declaration/route'; export { createPathFor } from './path/create-path-for'; diff --git a/src/routing/normalization/normalize-route-props.ts b/src/routing/normalization/normalize-route-props.ts index 21de20d..e9fb5b6 100644 --- a/src/routing/normalization/normalize-route-props.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -1,10 +1,9 @@ -import type { HttpRequest } from '@/Http'; +import type { HttpRequest, HttpRequestBase } from '@/Http'; import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; import type { RouterMethod } from '@/routing/declaration/router-method.type'; -import type { Request } from 'koa'; function resolveRouteOptions(options: RouteOptions): Pick { return { @@ -30,7 +29,7 @@ function qualifyMethods(method: HttpMethod | HttpMethod[]): RouterMethod[] { return qualifiedMethods.includes('all') ? ['all'] : [...new Set(qualifiedMethods)]; } -export function normalizeRouteProps( +export function normalizeRouteProps( routeProps: RouteProps, ): NormalizedRouteProps { return { diff --git a/src/routing/normalization/normalize-route-sources.ts b/src/routing/normalization/normalize-route-sources.ts index 26284c2..477d8fb 100644 --- a/src/routing/normalization/normalize-route-sources.ts +++ b/src/routing/normalization/normalize-route-sources.ts @@ -1,10 +1,10 @@ +import type { HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteGroupDefinition } from '@/routing/declaration/route-group'; +import type { RouteSource } from '@/routing/declaration/route-source.type'; import { mergeRouteOptions } from '@/routing/normalization/resolve-route-options'; -import type { Request } from 'koa'; -import type { RouteSource } from '../../declaration/route-source.type'; -interface NormalizationContext { +interface NormalizationContext { prefix: string; namePrefix: string; middleware: NormalizedRouteProps['middleware']; @@ -16,7 +16,7 @@ const defaultNormalizationContext = { middleware: [], }; -export function normalizeRouteSources( +export function normalizeRouteSources( routeSources: RouteSource[], context: NormalizationContext = defaultNormalizationContext, ): NormalizedRouteProps[] { @@ -34,7 +34,7 @@ export function normalizeRouteSources( return routes; } -function normalizeRouteGroup( +function normalizeRouteGroup( group: RouteGroupDefinition, parentContext: NormalizationContext, ): NormalizedRouteProps[] { @@ -43,7 +43,7 @@ function normalizeRouteGroup( return normalizeRouteSources(applyRouteConfig(group.resolveRoutes(), group), context); } -function createChildContext( +function createChildContext( group: RouteGroupDefinition, parentContext: NormalizationContext, ): NormalizationContext { @@ -57,7 +57,7 @@ function createChildContext( }; } -function normalizeRouteDefinition( +function normalizeRouteDefinition( route: NormalizedRouteProps, context: NormalizationContext, ): NormalizedRouteProps { @@ -69,7 +69,7 @@ function normalizeRouteDefinition( }; } -function applyRouteConfig( +function applyRouteConfig( routeSources: RouteSource[], group: RouteGroupDefinition, ): RouteSource[] { @@ -92,14 +92,14 @@ function applyRouteConfig( }); } -function resolveRouteConfigOptions( +function resolveRouteConfigOptions( route: NormalizedRouteProps, routeConfig: NonNullable['options']['routeConfig']>[string], ): Partial, 'parseBody' | 'bodyOptions'>> { return routeConfig.options ? mergeRouteOptions(route, routeConfig.options) : {}; } -function isRouteGroupDefinition( +function isRouteGroupDefinition( routeSource: RouteSource, ): routeSource is RouteGroupDefinition { return 'kind' in routeSource && routeSource.kind === 'route-group'; diff --git a/src/routing/normalization/resolve-route-options.ts b/src/routing/normalization/resolve-route-options.ts index 3d204a5..dc4cabf 100644 --- a/src/routing/normalization/resolve-route-options.ts +++ b/src/routing/normalization/resolve-route-options.ts @@ -1,6 +1,6 @@ +import type { HttpRequestBase } from '@/Http'; +import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; -import type { Request } from 'koa'; -import type { NormalizedRouteProps } from '../../declaration/normalized-route-props.type'; function extractBodyOptions(options: RouteOptions): NormalizedRouteProps['bodyOptions'] { const { parseBody: _parseBody, ...bodyOptions } = options; @@ -8,7 +8,7 @@ function extractBodyOptions(options: RouteOptions): NormalizedRouteProps['bodyOp return bodyOptions as NormalizedRouteProps['bodyOptions']; } -export function mergeRouteOptions( +export function mergeRouteOptions( route: NormalizedRouteProps, options: RouteOptions, ): Pick, 'parseBody' | 'bodyOptions'> { diff --git a/src/routing/registration/create-route-registrations.ts b/src/routing/registration/create-route-registrations.ts index 8681b91..8346c75 100644 --- a/src/routing/registration/create-route-registrations.ts +++ b/src/routing/registration/create-route-registrations.ts @@ -1,9 +1,9 @@ +import type { HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { Request } from 'koa'; import { koaBody } from 'koa-body'; -export function createRouteRegistrations( +export function createRouteRegistrations( routes: NormalizedRouteProps[], ): RouteRegistration[] { const registrations: RouteRegistration[] = []; @@ -15,7 +15,7 @@ export function createRouteRegistrations( return registrations; } -function createRouteRegistration( +function createRouteRegistration( route: NormalizedRouteProps, ): RouteRegistration[] { const middleware = resolveRouteMiddleware(route); @@ -27,7 +27,7 @@ function createRouteRegistration( })); } -function resolveRouteMiddleware( +function resolveRouteMiddleware( route: NormalizedRouteProps, ): RouteRegistration['middleware'] { const middlewareStack = [...route.middleware, route.handler]; diff --git a/src/routing/registration/register-routes.ts b/src/routing/registration/register-routes.ts index da73733..daa3452 100644 --- a/src/routing/registration/register-routes.ts +++ b/src/routing/registration/register-routes.ts @@ -1,13 +1,13 @@ import { type Application } from '@/application/application'; -import { type HttpScope } from '@/Http'; +import { type HttpRequestBase, type HttpScope } from '@/Http'; import type { RouteSource } from '@/routing/declaration/route-source.type'; import { normalizeRouteSources } from '@/routing/normalization/normalize-route-sources'; import { createRouteRegistrations } from '@/routing/registration/create-route-registrations'; import { validateRouteRegistrations } from '@/routing/registration/validate-route-registrations'; import Router, { type RouterInstance } from '@koa/router'; -import { type DefaultContext, type DefaultState, type Middleware, type Request } from 'koa'; +import { type DefaultContext, type DefaultState, type Middleware } from 'koa'; -export function registerRoutes( +export function registerRoutes( app: Application, routes: RouteSource[] = [], ): Application { @@ -19,7 +19,7 @@ export function registerRoutes( return app; } -function createRouter(routeSources: RouteSource[]): RouterInstance { +function createRouter(routeSources: RouteSource[]): RouterInstance { const router = new Router(); const routes = normalizeRouteSources(routeSources); const registrations = createRouteRegistrations(routes); diff --git a/src/routing/registration/route-registration.ts b/src/routing/registration/route-registration.ts index fb774fc..77b9cba 100644 --- a/src/routing/registration/route-registration.ts +++ b/src/routing/registration/route-registration.ts @@ -1,13 +1,12 @@ -import type { HttpRequest } from '@/Http'; +import type { HttpRequest, HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouterMethod } from '@/routing/declaration/router-method.type'; -import type { Request } from 'koa'; -type RouteRegistrationMiddleware = +type RouteRegistrationMiddleware = | NormalizedRouteProps['middleware'][number] | NormalizedRouteProps['handler']; -export interface RouteRegistration { +export interface RouteRegistration { method: RouterMethod; path: string; middleware: RouteRegistrationMiddleware[]; diff --git a/src/routing/registration/validate-route-registrations.ts b/src/routing/registration/validate-route-registrations.ts index 0a7c309..ecdee74 100644 --- a/src/routing/registration/validate-route-registrations.ts +++ b/src/routing/registration/validate-route-registrations.ts @@ -1,8 +1,8 @@ +import type { HttpRequestBase } from '@/Http'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteRegistration } from '@/routing/registration/route-registration'; -import type { Request } from 'koa'; -export function validateRouteRegistrations( +export function validateRouteRegistrations( routes: NormalizedRouteProps[], registrations: RouteRegistration[], ): void { @@ -10,7 +10,9 @@ export function validateRouteRegistrations( validateUniqueRouteSignatures(registrations); } -function validateUniqueRouteSignatures(registrations: RouteRegistration[]): void { +function validateUniqueRouteSignatures( + registrations: RouteRegistration[], +): void { const signatures = new Set(); for (const registration of registrations) { @@ -24,7 +26,7 @@ function validateUniqueRouteSignatures(registrations: } } -function validateUniqueRouteNames(routes: NormalizedRouteProps[]): void { +function validateUniqueRouteNames(routes: NormalizedRouteProps[]): void { const routeNames = new Set(); for (const route of routes) { From be8017ecaff41347e803011a9a6ed3f88e807ed0 Mon Sep 17 00:00:00 2001 From: Dhemy Date: Thu, 4 Jun 2026 12:50:25 +0200 Subject: [PATCH 45/45] wip: move http method type to root --- src/index.ts | 2 +- src/routing/declaration/http-verb-helpers.ts | 2 +- src/routing/declaration/route-props.type.ts | 2 +- src/routing/deprecated-decorator/route.ts | 2 +- src/routing/{declaration => }/http-method.type.ts | 0 src/routing/index.ts | 3 +-- src/routing/normalization/normalize-route-props.ts | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) rename src/routing/{declaration => }/http-method.type.ts (100%) diff --git a/src/index.ts b/src/index.ts index cadcefd..f877075 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export * from '@/Kernel'; // Routing export * from '@/routing/deprecated-decorator/route'; -export type { HttpMethod } from '@/routing/declaration/http-method.type'; +export type { HttpMethod } from '@/routing/http-method.type'; export type { RouteOptions } from '@/routing/declaration/route-options.type'; export type { RouterMethod } from '@/routing/declaration/router-method.type'; /** diff --git a/src/routing/declaration/http-verb-helpers.ts b/src/routing/declaration/http-verb-helpers.ts index 09fa6a5..6538ad0 100644 --- a/src/routing/declaration/http-verb-helpers.ts +++ b/src/routing/declaration/http-verb-helpers.ts @@ -1,7 +1,7 @@ import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; -import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import { Route } from '@/routing/declaration/route'; +import type { HttpMethod } from '@/routing/http-method.type'; type RouteHandler = HttpMiddleware; type MiddlewareAndHandler = [ diff --git a/src/routing/declaration/route-props.type.ts b/src/routing/declaration/route-props.type.ts index dd0101f..9592dcd 100644 --- a/src/routing/declaration/route-props.type.ts +++ b/src/routing/declaration/route-props.type.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware, HttpRequest, HttpRequestBase } from '@/Http'; -import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; +import type { HttpMethod } from '@/routing/http-method.type'; export interface RouteProps { name?: string; diff --git a/src/routing/deprecated-decorator/route.ts b/src/routing/deprecated-decorator/route.ts index 7dda963..ce4ffcd 100644 --- a/src/routing/deprecated-decorator/route.ts +++ b/src/routing/deprecated-decorator/route.ts @@ -1,6 +1,6 @@ import type { HttpMiddleware } from '@/Http'; -import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; +import type { HttpMethod } from '@/routing/http-method.type'; import { createLegacyRouteDecorator } from './legacy-router'; /** diff --git a/src/routing/declaration/http-method.type.ts b/src/routing/http-method.type.ts similarity index 100% rename from src/routing/declaration/http-method.type.ts rename to src/routing/http-method.type.ts diff --git a/src/routing/index.ts b/src/routing/index.ts index bc73de0..5d8006d 100644 --- a/src/routing/index.ts +++ b/src/routing/index.ts @@ -1,5 +1,4 @@ -export type { HttpMethod } from '@/routing/declaration/http-method.type'; -export type { RouteOptions } from '@/routing/declaration/route-options.type'; +export type { HttpMethod } from '@/routing/http-method.type'; export type { RouteSource } from '@/routing/declaration/route-source.type'; export { Route } from './declaration/route'; export { createPathFor } from './path/create-path-for'; diff --git a/src/routing/normalization/normalize-route-props.ts b/src/routing/normalization/normalize-route-props.ts index e9fb5b6..6b71b33 100644 --- a/src/routing/normalization/normalize-route-props.ts +++ b/src/routing/normalization/normalize-route-props.ts @@ -1,9 +1,9 @@ import type { HttpRequest, HttpRequestBase } from '@/Http'; -import type { HttpMethod } from '@/routing/declaration/http-method.type'; import type { NormalizedRouteProps } from '@/routing/declaration/normalized-route-props.type'; import type { RouteOptions } from '@/routing/declaration/route-options.type'; import { RouteProps } from '@/routing/declaration/route-props.type'; import type { RouterMethod } from '@/routing/declaration/router-method.type'; +import type { HttpMethod } from '@/routing/http-method.type'; function resolveRouteOptions(options: RouteOptions): Pick { return {