@webpieces/http-routing 0.2.11 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/http-routing",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Decorator-based routing with auto-wiring for WebPieces",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -21,7 +21,7 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@webpieces/core-meta": "0.2.11",
25
- "@webpieces/http-api": "0.2.11"
24
+ "@webpieces/core-meta": "0.2.13",
25
+ "@webpieces/http-api": "0.2.13"
26
26
  }
27
27
  }
@@ -56,19 +56,6 @@ export declare class RESTApiRoutes<TApi = any, TController extends TApi = any> i
56
56
  * Register a single route with the route builder.
57
57
  */
58
58
  private registerRoute;
59
- /**
60
- * Create a typed route handler for a specific route.
61
- *
62
- * The handler:
63
- * 1. Resolves the controller from the DI container
64
- * 2. Invokes the controller method with extracted parameters
65
- * 3. Returns the controller method result
66
- *
67
- * Type parameter TResult represents the return type of the controller method.
68
- * At runtime, we can't enforce this statically, but TypeScript will infer it
69
- * from the method signature on the API interface.
70
- */
71
- private createRouteHandler;
72
59
  /**
73
60
  * Get the filepath of the controller source file.
74
61
  * Uses a heuristic based on the controller class name.
@@ -84,43 +84,9 @@ class RESTApiRoutes {
84
84
  }
85
85
  // Extract controller filepath for filter matching
86
86
  const controllerFilepath = this.getControllerFilepath();
87
- // Create typed route handler
88
- // The handler's return type is inferred from the controller method's return type
89
- const routeHandler = this.createRouteHandler(route);
90
- routeBuilder.addRoute(new core_meta_1.RouteDefinition(route.httpMethod, route.path, routeHandler, controllerFilepath));
91
- }
92
- /**
93
- * Create a typed route handler for a specific route.
94
- *
95
- * The handler:
96
- * 1. Resolves the controller from the DI container
97
- * 2. Invokes the controller method with extracted parameters
98
- * 3. Returns the controller method result
99
- *
100
- * Type parameter TResult represents the return type of the controller method.
101
- * At runtime, we can't enforce this statically, but TypeScript will infer it
102
- * from the method signature on the API interface.
103
- */
104
- createRouteHandler(route) {
105
- const controllerClass = this.controllerClass;
106
- return new class extends core_meta_1.RouteHandler {
107
- async execute(context) {
108
- const { container, params } = context;
109
- // Resolve controller instance from DI container
110
- const controller = container.get(controllerClass);
111
- // Get the controller method
112
- const method = controller[route.methodName];
113
- if (typeof method !== 'function') {
114
- const controllerName = controllerClass.name || 'Unknown';
115
- throw new Error(`Method ${route.methodName} not found on controller ${controllerName}`);
116
- }
117
- // Invoke the method with parameters and return the result
118
- // TypeScript trusts that the method returns Promise<TResult> based on
119
- // the interface definition (e.g., SaveApi.save returns Promise<SaveResponse>)
120
- const result = await method.apply(controller, params);
121
- return result;
122
- }
123
- };
87
+ // Pass controller class and method name to RouteBuilder
88
+ // RouteBuilder will resolve the controller from DI and create the handler
89
+ routeBuilder.addRoute(new core_meta_1.RouteDefinition(route, this.controllerClass, controllerFilepath));
124
90
  }
125
91
  /**
126
92
  * Get the filepath of the controller source file.
@@ -1 +1 @@
1
- {"version":3,"file":"RESTApiRoutes.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/RESTApiRoutes.ts"],"names":[],"mappings":";;;AAAA,oDAAyG;AACzG,kDAA+E;AAC/E,6CAAqD;AAOrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,aAAa;IAIxB;;;;;OAKG;IACH,YAAY,YAA6B,EAAE,eAAuC;QAChF,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,wDAAwD;QACxD,IAAI,CAAC,IAAA,yBAAc,EAAC,YAAY,CAAC,EAAE,CAAC;YAClC,MAAM,SAAS,GAAI,YAAoB,CAAC,IAAI,IAAI,SAAS,CAAC;YAC1D,MAAM,IAAI,KAAK,CACb,SAAS,SAAS,yCAAyC,CAC5D,CAAC;Q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,CAAC,eAAe,CACrB,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,iCAAiC;QACjC,MAAM,SAAS,GAAI,IAAI,CAAC,eAAuB,CAAC,IAAI,CAAC;QACrD,OAAO,SAAS,CAAC,CAAC,CAAC,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AAlKD,sCAkKC","sourcesContent":["import { Routes, RouteBuilder, RouteHandler, RouteContext, RouteDefinition } from '@webpieces/core-meta';\nimport { getRoutes, isApiInterface, RouteMetadata } from '@webpieces/http-api';\nimport { ROUTING_METADATA_KEYS } from './decorators';\n\n/**\n * Type representing a class constructor (abstract or concrete).\n */\nexport type ClassType<T = any> = Function & { prototype: T };\n\n/**\n * RESTApiRoutes - Automatically wire API interfaces to controllers.\n * Similar to Java WebPieces RESTApiRoutes.\n *\n * This class uses reflection (reflect-metadata) to read decorators from\n * an API interface class and automatically register routes that dispatch\n * to the corresponding controller methods.\n *\n * Usage:\n * ```typescript\n * // In your ServerMeta:\n * getRoutes(): Routes[] {\n * return [\n * new RESTApiRoutes(SaveApiPrototype, SaveController),\n * // ... more routes\n * ];\n * }\n * ```\n *\n * The API interface and controller must follow this pattern:\n * - API interface class has @ApiInterface() decorator\n * - Methods have @Post()/@Get()/etc and @Path() decorators\n * - Controller class implements the same interface\n * - Controller class has @Controller() decorator\n *\n * Type Parameters:\n * - TApi: The API prototype class type (abstract class with decorators)\n * - TController: The controller class type (must extend TApi)\n */\nexport class RESTApiRoutes<TApi = any, TController extends TApi = any> implements Routes {\n private apiMetaClass: ClassType<TApi>;\n private controllerClass: ClassType<TController>;\n\n /**\n * Create a new RESTApiRoutes.\n *\n * @param apiMetaClass - The API interface class with decorators (e.g., SaveApiPrototype)\n * @param controllerClass - The controller class that implements the API (e.g., SaveController)\n */\n constructor(apiMetaClass: ClassType<TApi>, controllerClass: ClassType<TController>) {\n this.apiMetaClass = apiMetaClass;\n this.controllerClass = controllerClass;\n\n // Validate that apiMetaClass is marked as @ApiInterface\n if (!isApiInterface(apiMetaClass)) {\n const className = (apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Class ${className} must be decorated with @ApiInterface()`\n );\n }\n\n // Validate that controllerClass implements the methods from apiMetaClass\n this.validateControllerImplementsApi();\n }\n\n /**\n * Validate that the controller implements all methods from the API interface.\n */\n private validateControllerImplementsApi(): void {\n const routes = getRoutes(this.apiMetaClass);\n\n for (const route of routes) {\n const controllerPrototype = this.controllerClass.prototype;\n\n if (typeof controllerPrototype[route.methodName] !== 'function') {\n const controllerName = (this.controllerClass as any).name || 'Unknown';\n const apiName = (this.apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Controller ${controllerName} must implement method ${route.methodName} from API ${apiName}`\n );\n }\n }\n }\n\n /**\n * Configure routes by reading metadata from the API interface.\n */\n configure(routeBuilder: RouteBuilder): void {\n const routes = getRoutes(this.apiMetaClass);\n\n for (const route of routes) {\n this.registerRoute(routeBuilder, route);\n }\n }\n\n /**\n * Register a single route with the route builder.\n */\n private registerRoute(routeBuilder: RouteBuilder, route: RouteMetadata): void {\n if (!route.httpMethod || !route.path) {\n const apiName = (this.apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Method ${route.methodName} in ${apiName} must have both @HttpMethod and @Path decorators`\n );\n }\n\n // Extract controller filepath for filter matching\n const controllerFilepath = this.getControllerFilepath();\n\n // Create typed route handler\n // The handler's return type is inferred from the controller method's return type\n const routeHandler: RouteHandler<unknown> = this.createRouteHandler(route);\n\n routeBuilder.addRoute(\n new RouteDefinition(\n route.httpMethod,\n route.path,\n routeHandler,\n controllerFilepath\n )\n );\n }\n\n /**\n * Create a typed route handler for a specific route.\n *\n * The handler:\n * 1. Resolves the controller from the DI container\n * 2. Invokes the controller method with extracted parameters\n * 3. Returns the controller method result\n *\n * Type parameter TResult represents the return type of the controller method.\n * At runtime, we can't enforce this statically, but TypeScript will infer it\n * from the method signature on the API interface.\n */\n private createRouteHandler<TResult = unknown>(route: RouteMetadata): RouteHandler<TResult> {\n const controllerClass = this.controllerClass;\n\n return new class extends RouteHandler<TResult> {\n async execute(context: RouteContext): Promise<TResult> {\n const { container, params } = context;\n\n // Resolve controller instance from DI container\n const controller = container.get(controllerClass) as TController;\n\n // Get the controller method\n const method = (controller as any)[route.methodName];\n if (typeof method !== 'function') {\n const controllerName = (controllerClass as any).name || 'Unknown';\n throw new Error(\n `Method ${route.methodName} not found on controller ${controllerName}`\n );\n }\n\n // Invoke the method with parameters and return the result\n // TypeScript trusts that the method returns Promise<TResult> based on\n // the interface definition (e.g., SaveApi.save returns Promise<SaveResponse>)\n const result: TResult = await method.apply(controller, params);\n\n return result;\n }\n };\n }\n\n /**\n * Get the filepath of the controller source file.\n * Uses a heuristic based on the controller class name.\n *\n * Since TypeScript doesn't provide source file paths at runtime,\n * we use the class name to create a pattern that filters can match against.\n *\n * @returns Filepath pattern or undefined\n */\n private getControllerFilepath(): string | undefined {\n // Check for explicit @SourceFile decorator metadata\n const filepath = Reflect.getMetadata(\n ROUTING_METADATA_KEYS.SOURCE_FILEPATH,\n this.controllerClass\n );\n if (filepath) {\n return filepath;\n }\n\n // Fallback to class name pattern\n const className = (this.controllerClass as any).name;\n return className ? `**/${className}.ts` : undefined;\n }\n\n /**\n * Get the API interface class.\n */\n getApiClass(): any {\n return this.apiMetaClass;\n }\n\n /**\n * Get the controller class.\n */\n getControllerClass(): any {\n return this.controllerClass;\n }\n}\n"]}
1
+ {"version":3,"file":"RESTApiRoutes.js","sourceRoot":"","sources":["../../../../../packages/http/http-routing/src/RESTApiRoutes.ts"],"names":[],"mappings":";;;AAAA,oDAA6E;AAC7E,kDAA+E;AAC/E,6CAAqD;AAOrD;;;;;;;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Y,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,YAA0B,EAAE,KAAoB;QACpE,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YACrC,MAAM,OAAO,GAAI,IAAI,CAAC,YAAoB,CAAC,IAAI,IAAI,SAAS,CAAC;YAC7D,MAAM,IAAI,KAAK,CACb,UAAU,KAAK,CAAC,UAAU,OAAO,OAAO,kDAAkD,CAC3F,CAAC;QACJ,CAAC;QAED,kDAAkD;QAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAExD,wDAAwD;QACxD,0EAA0E;QAC1E,YAAY,CAAC,QAAQ,CACnB,IAAI,2BAAe,CACf,KAAK,EACP,IAAI,CAAC,eAAe,EACpB,kBAAkB,CACnB,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACK,qBAAqB;QAC3B,oDAAoD;QACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAClC,kCAAqB,CAAC,eAAe,EACrC,IAAI,CAAC,eAAe,CACrB,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,iCAAiC;QACjC,MAAM,SAAS,GAAI,IAAI,CAAC,eAAuB,CAAC,IAAI,CAAC;QACrD,OAAO,SAAS,CAAC,CAAC,CAAC,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AAtHD,sCAsHC","sourcesContent":["import { Routes, RouteBuilder, RouteDefinition } from '@webpieces/core-meta';\nimport { getRoutes, isApiInterface, RouteMetadata } from '@webpieces/http-api';\nimport { ROUTING_METADATA_KEYS } from './decorators';\n\n/**\n * Type representing a class constructor (abstract or concrete).\n */\nexport type ClassType<T = any> = Function & { prototype: T };\n\n/**\n * RESTApiRoutes - Automatically wire API interfaces to controllers.\n * Similar to Java WebPieces RESTApiRoutes.\n *\n * This class uses reflection (reflect-metadata) to read decorators from\n * an API interface class and automatically register routes that dispatch\n * to the corresponding controller methods.\n *\n * Usage:\n * ```typescript\n * // In your ServerMeta:\n * getRoutes(): Routes[] {\n * return [\n * new RESTApiRoutes(SaveApiPrototype, SaveController),\n * // ... more routes\n * ];\n * }\n * ```\n *\n * The API interface and controller must follow this pattern:\n * - API interface class has @ApiInterface() decorator\n * - Methods have @Post()/@Get()/etc and @Path() decorators\n * - Controller class implements the same interface\n * - Controller class has @Controller() decorator\n *\n * Type Parameters:\n * - TApi: The API prototype class type (abstract class with decorators)\n * - TController: The controller class type (must extend TApi)\n */\nexport class RESTApiRoutes<TApi = any, TController extends TApi = any> implements Routes {\n private apiMetaClass: ClassType<TApi>;\n private controllerClass: ClassType<TController>;\n\n /**\n * Create a new RESTApiRoutes.\n *\n * @param apiMetaClass - The API interface class with decorators (e.g., SaveApiPrototype)\n * @param controllerClass - The controller class that implements the API (e.g., SaveController)\n */\n constructor(apiMetaClass: ClassType<TApi>, controllerClass: ClassType<TController>) {\n this.apiMetaClass = apiMetaClass;\n this.controllerClass = controllerClass;\n\n // Validate that apiMetaClass is marked as @ApiInterface\n if (!isApiInterface(apiMetaClass)) {\n const className = (apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Class ${className} must be decorated with @ApiInterface()`\n );\n }\n\n // Validate that controllerClass implements the methods from apiMetaClass\n this.validateControllerImplementsApi();\n }\n\n /**\n * Validate that the controller implements all methods from the API interface.\n */\n private validateControllerImplementsApi(): void {\n const routes = getRoutes(this.apiMetaClass);\n\n for (const route of routes) {\n const controllerPrototype = this.controllerClass.prototype;\n\n if (typeof controllerPrototype[route.methodName] !== 'function') {\n const controllerName = (this.controllerClass as any).name || 'Unknown';\n const apiName = (this.apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Controller ${controllerName} must implement method ${route.methodName} from API ${apiName}`\n );\n }\n }\n }\n\n /**\n * Configure routes by reading metadata from the API interface.\n */\n configure(routeBuilder: RouteBuilder): void {\n const routes = getRoutes(this.apiMetaClass);\n\n for (const route of routes) {\n this.registerRoute(routeBuilder, route);\n }\n }\n\n /**\n * Register a single route with the route builder.\n */\n private registerRoute(routeBuilder: RouteBuilder, route: RouteMetadata): void {\n if (!route.httpMethod || !route.path) {\n const apiName = (this.apiMetaClass as any).name || 'Unknown';\n throw new Error(\n `Method ${route.methodName} in ${apiName} must have both @HttpMethod and @Path decorators`\n );\n }\n\n // Extract controller filepath for filter matching\n const controllerFilepath = this.getControllerFilepath();\n\n // Pass controller class and method name to RouteBuilder\n // RouteBuilder will resolve the controller from DI and create the handler\n routeBuilder.addRoute(\n new RouteDefinition(\n route,\n this.controllerClass,\n controllerFilepath\n )\n );\n }\n\n /**\n * Get the filepath of the controller source file.\n * Uses a heuristic based on the controller class name.\n *\n * Since TypeScript doesn't provide source file paths at runtime,\n * we use the class name to create a pattern that filters can match against.\n *\n * @returns Filepath pattern or undefined\n */\n private getControllerFilepath(): string | undefined {\n // Check for explicit @SourceFile decorator metadata\n const filepath = Reflect.getMetadata(\n ROUTING_METADATA_KEYS.SOURCE_FILEPATH,\n this.controllerClass\n );\n if (filepath) {\n return filepath;\n }\n\n // Fallback to class name pattern\n const className = (this.controllerClass as any).name;\n return className ? `**/${className}.ts` : undefined;\n }\n\n /**\n * Get the API interface class.\n */\n getApiClass(): any {\n return this.apiMetaClass;\n }\n\n /**\n * Get the controller class.\n */\n getControllerClass(): any {\n return this.controllerClass;\n }\n}\n"]}