inviton-backduck 1.0.0

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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +302 -0
  3. package/dist/apidoc/api-doc-generator.d.ts +58 -0
  4. package/dist/apidoc/api-doc-generator.d.ts.map +1 -0
  5. package/dist/apidoc/api-doc-generator.js +201 -0
  6. package/dist/apidoc/api-doc-generator.js.map +1 -0
  7. package/dist/apidoc/config.d.ts +153 -0
  8. package/dist/apidoc/config.d.ts.map +1 -0
  9. package/dist/apidoc/config.js +254 -0
  10. package/dist/apidoc/config.js.map +1 -0
  11. package/dist/apidoc/controller-parser.d.ts +208 -0
  12. package/dist/apidoc/controller-parser.d.ts.map +1 -0
  13. package/dist/apidoc/controller-parser.js +686 -0
  14. package/dist/apidoc/controller-parser.js.map +1 -0
  15. package/dist/apidoc/html-generator.d.ts +290 -0
  16. package/dist/apidoc/html-generator.d.ts.map +1 -0
  17. package/dist/apidoc/html-generator.js +2295 -0
  18. package/dist/apidoc/html-generator.js.map +1 -0
  19. package/dist/apidoc/index.d.ts +20 -0
  20. package/dist/apidoc/index.d.ts.map +1 -0
  21. package/dist/apidoc/index.js +16 -0
  22. package/dist/apidoc/index.js.map +1 -0
  23. package/dist/apidoc/openapi-builder.d.ts +169 -0
  24. package/dist/apidoc/openapi-builder.d.ts.map +1 -0
  25. package/dist/apidoc/openapi-builder.js +634 -0
  26. package/dist/apidoc/openapi-builder.js.map +1 -0
  27. package/dist/apidoc/parameterGeneratorRegistry.d.ts +20 -0
  28. package/dist/apidoc/parameterGeneratorRegistry.d.ts.map +1 -0
  29. package/dist/apidoc/parameterGeneratorRegistry.js +6 -0
  30. package/dist/apidoc/parameterGeneratorRegistry.js.map +1 -0
  31. package/dist/apidoc/test-type-resolver.d.ts +2 -0
  32. package/dist/apidoc/test-type-resolver.d.ts.map +1 -0
  33. package/dist/apidoc/test-type-resolver.js +6 -0
  34. package/dist/apidoc/test-type-resolver.js.map +1 -0
  35. package/dist/apidoc/type-resolver.d.ts +266 -0
  36. package/dist/apidoc/type-resolver.d.ts.map +1 -0
  37. package/dist/apidoc/type-resolver.js +1226 -0
  38. package/dist/apidoc/type-resolver.js.map +1 -0
  39. package/dist/apidoc/verify-type-resolution.d.ts +3 -0
  40. package/dist/apidoc/verify-type-resolution.d.ts.map +1 -0
  41. package/dist/apidoc/verify-type-resolution.js +29 -0
  42. package/dist/apidoc/verify-type-resolution.js.map +1 -0
  43. package/dist/bun/bunRouter.d.ts +70 -0
  44. package/dist/bun/bunRouter.d.ts.map +1 -0
  45. package/dist/bun/bunRouter.js +324 -0
  46. package/dist/bun/bunRouter.js.map +1 -0
  47. package/dist/bun/bunServer.d.ts +72 -0
  48. package/dist/bun/bunServer.d.ts.map +1 -0
  49. package/dist/bun/bunServer.js +218 -0
  50. package/dist/bun/bunServer.js.map +1 -0
  51. package/dist/bun/bunStaticFiles.d.ts +76 -0
  52. package/dist/bun/bunStaticFiles.d.ts.map +1 -0
  53. package/dist/bun/bunStaticFiles.js +251 -0
  54. package/dist/bun/bunStaticFiles.js.map +1 -0
  55. package/dist/bun/index.d.ts +7 -0
  56. package/dist/bun/index.d.ts.map +1 -0
  57. package/dist/bun/index.js +7 -0
  58. package/dist/bun/index.js.map +1 -0
  59. package/dist/data-contracts.d.ts +132 -0
  60. package/dist/data-contracts.d.ts.map +1 -0
  61. package/dist/data-contracts.js +2 -0
  62. package/dist/data-contracts.js.map +1 -0
  63. package/dist/decorators.d.ts +75 -0
  64. package/dist/decorators.d.ts.map +1 -0
  65. package/dist/decorators.js +101 -0
  66. package/dist/decorators.js.map +1 -0
  67. package/dist/express/expressFrontendRouter.d.ts +17 -0
  68. package/dist/express/expressFrontendRouter.d.ts.map +1 -0
  69. package/dist/express/expressFrontendRouter.js +33 -0
  70. package/dist/express/expressFrontendRouter.js.map +1 -0
  71. package/dist/express/expressRouter.d.ts +25 -0
  72. package/dist/express/expressRouter.d.ts.map +1 -0
  73. package/dist/express/expressRouter.js +150 -0
  74. package/dist/express/expressRouter.js.map +1 -0
  75. package/dist/express/index.d.ts +6 -0
  76. package/dist/express/index.d.ts.map +1 -0
  77. package/dist/express/index.js +6 -0
  78. package/dist/express/index.js.map +1 -0
  79. package/dist/index.d.ts +47 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +52 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/router.d.ts +162 -0
  84. package/dist/router.d.ts.map +1 -0
  85. package/dist/router.js +350 -0
  86. package/dist/router.js.map +1 -0
  87. package/dist/runtime-detect.d.ts +20 -0
  88. package/dist/runtime-detect.d.ts.map +1 -0
  89. package/dist/runtime-detect.js +20 -0
  90. package/dist/runtime-detect.js.map +1 -0
  91. package/dist/server.d.ts +126 -0
  92. package/dist/server.d.ts.map +1 -0
  93. package/dist/server.js +181 -0
  94. package/dist/server.js.map +1 -0
  95. package/dist/utils.d.ts +83 -0
  96. package/dist/utils.d.ts.map +1 -0
  97. package/dist/utils.js +157 -0
  98. package/dist/utils.js.map +1 -0
  99. package/package.json +65 -0
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @server-runtime - Runtime-agnostic utilities for building web servers
3
+ *
4
+ * This package provides a unified API for building web servers that can run on
5
+ * both Node.js (with Express) and Bun natively. Write your server code once,
6
+ * and it will automatically adapt to the runtime environment.
7
+ *
8
+ * Key Features:
9
+ * - Universal Router: Define routes once, run anywhere
10
+ * - Controller-based routing with automatic REST mapping
11
+ * - Runtime detection and automatic adaptation
12
+ * - Type-safe request/response handling
13
+ * - Middleware support with chaining
14
+ * - Static file serving with compression
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { createRouter, createServer, Route, ControllerBase } from '@server-runtime';
19
+ *
20
+ * // Define a controller
21
+ * @Route('/products')
22
+ * class ProductController extends ControllerBase {
23
+ * async getAll() { return products; }
24
+ * async get(args: { id: number }) { return product; }
25
+ * async post(args: CreateProductArgs) { return created; }
26
+ * }
27
+ *
28
+ * // Create router and register controllers
29
+ * const router = createRouter();
30
+ * router.registerController(ProductController);
31
+ *
32
+ * // Create and start server
33
+ * const server = createServer({
34
+ * port: 3000,
35
+ * apiRouters: { '/api': router }
36
+ * });
37
+ * await server.start();
38
+ * ```
39
+ */
40
+ // API Documentation - Generate OpenAPI and HTML documentation from TypeScript controllers
41
+ export * from './apidoc';
42
+ // Decorators - Controller and route configuration
43
+ export { ControllerGetMiddlewares, Middleware as MiddlewareDecorator, ParseRequestArgs, RequestSize, Route, } from './decorators';
44
+ // Router - Route definition and controller registration
45
+ export { ControllerBase, createRouter, WebRouter as UniversalRouter, WebRouter, } from './router';
46
+ // Runtime detection - Detect current runtime environment
47
+ export { IS_BUN, RUNTIME } from './runtime-detect';
48
+ // Server - Server creation and configuration
49
+ export { createServer, UniversalServer, } from './server';
50
+ // Utils - Request parsing and helper utilities
51
+ export { RuntimeUtils } from './utils';
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,0FAA0F;AAC1F,cAAc,UAAU,CAAC;AAYzB,kDAAkD;AAClD,OAAO,EACN,wBAAwB,EACxB,UAAU,IAAI,mBAAmB,EACjC,gBAAgB,EAChB,WAAW,EACX,KAAK,GACL,MAAM,cAAc,CAAC;AAEtB,wDAAwD;AACxD,OAAO,EACN,cAAc,EACd,YAAY,EAGZ,SAAS,IAAI,eAAe,EAC5B,SAAS,GACT,MAAM,UAAU,CAAC;AAElB,yDAAyD;AACzD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEnD,6CAA6C;AAC7C,OAAO,EAEN,YAAY,EAGZ,eAAe,GAEf,MAAM,UAAU,CAAC;AAElB,+CAA+C;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Universal Router - Runtime-agnostic router that builds to Express or Bun natively
3
+ */
4
+ import type { Router as ExpressRouter } from 'express';
5
+ import type { BunRouter } from './bun';
6
+ import type { MiddlewareDefinition, RouteHandler, WebRequest, WebResponse } from './data-contracts';
7
+ /**
8
+ * HTTP methods supported by the router
9
+ */
10
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
11
+ /**
12
+ * Controller interface for automatic route binding
13
+ * Controllers implement standard REST methods that are automatically mapped to routes
14
+ */
15
+ export interface IController {
16
+ /** Base route path for the controller */
17
+ $route?: string;
18
+ /** Authentication function that runs before route handlers */
19
+ $auth?: (req: WebRequest, res: WebResponse) => Promise<boolean>;
20
+ /** Request body size limit (Express only) */
21
+ $requestSize?: string;
22
+ /** Middleware functions to run before route handlers */
23
+ $middlewares?: MiddlewareDefinition[];
24
+ /** GET handler for listing resources (mapped to GET /) */
25
+ getAll?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
26
+ /** GET handler for fetching single resource (mapped to GET /:id) */
27
+ get?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
28
+ /** POST handler for creating resources (mapped to POST /) */
29
+ post?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
30
+ /** PATCH handler for partial updates (mapped to PATCH /:id) */
31
+ patch?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
32
+ /** PUT handler for full updates (mapped to PUT /:id) */
33
+ put?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
34
+ /** DELETE handler for removing resources (mapped to DELETE /:id) */
35
+ delete?: <TRequest, TResponse>(args: TRequest, req?: WebRequest, res?: WebResponse) => Promise<TResponse>;
36
+ }
37
+ /**
38
+ * Base class for controllers that provides automatic route binding
39
+ */
40
+ export declare class ControllerBase implements IController {
41
+ }
42
+ export type { BunNativeRoutes, BunRouteDefinition } from './bun';
43
+ export { BunRouter } from './bun';
44
+ /**
45
+ * Universal Router - define routes once, build for Express or Bun
46
+ * Provides a runtime-agnostic API for defining HTTP routes and middleware
47
+ */
48
+ export declare class WebRouter {
49
+ private routes;
50
+ private subRouters;
51
+ private globalMiddlewares;
52
+ /**
53
+ * Add global middleware or mount a sub-router
54
+ * @param middleware - Middleware function to apply to all routes
55
+ * @param path - Path prefix for mounting a sub-router
56
+ * @param router - Sub-router to mount at the given path
57
+ * @returns This router instance for chaining
58
+ */
59
+ use(middleware: MiddlewareDefinition): this;
60
+ use(path: string, router: WebRouter): this;
61
+ /**
62
+ * Register a GET route
63
+ * @param path - URL path (supports :param and * wildcards)
64
+ * @param handlers - Middleware and route handler functions
65
+ * @returns This router instance for chaining
66
+ */
67
+ get(path: string, ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
68
+ /**
69
+ * Register a POST route
70
+ * @param path - URL path (supports :param and * wildcards)
71
+ * @param handlers - Middleware and route handler functions
72
+ * @returns This router instance for chaining
73
+ */
74
+ post(path: string, ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
75
+ /**
76
+ * Register a PUT route
77
+ * @param path - URL path (supports :param and * wildcards)
78
+ * @param handlers - Middleware and route handler functions
79
+ * @returns This router instance for chaining
80
+ */
81
+ put(path: string, ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
82
+ /**
83
+ * Register a PATCH route
84
+ * @param path - URL path (supports :param and * wildcards)
85
+ * @param handlers - Middleware and route handler functions
86
+ * @returns This router instance for chaining
87
+ */
88
+ patch(path: string, ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
89
+ /**
90
+ * Register a DELETE route
91
+ * @param path - URL path (supports :param and * wildcards)
92
+ * @param handlers - Middleware and route handler functions
93
+ * @returns This router instance for chaining
94
+ */
95
+ delete(path: string, ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
96
+ /**
97
+ * Register a GET route with a regex pattern
98
+ * Useful for complex pattern matching (e.g., SPA routes with locale prefixes)
99
+ * @param pattern - Regular expression for matching the URL path
100
+ * @param paramNames - Names for captured groups in the regex
101
+ * @param handlers - Middleware and route handler functions
102
+ * @returns This router instance for chaining
103
+ * @example
104
+ * ```typescript
105
+ * router.getRegex(/^\/(en|sk|cs)\/products$/, ['locale'], (req, res) => {
106
+ * const locale = req.params.locale; // 'en', 'sk', or 'cs'
107
+ * });
108
+ * ```
109
+ */
110
+ getRegex(pattern: RegExp, paramNames: string[], ...handlers: (RouteHandler | MiddlewareDefinition)[]): this;
111
+ private addRegexRoute;
112
+ /**
113
+ * Register a controller class with automatic route binding
114
+ * Maps controller methods (get, post, etc.) to HTTP routes automatically
115
+ * @param ControllerClass - Controller class to register
116
+ * @returns This router instance for chaining
117
+ * @example
118
+ * ```typescript
119
+ * @Route('/products')
120
+ * class ProductController extends ControllerBase {
121
+ * async getAll() { return products; } // GET /products
122
+ * async get(args: { id: number }) { return product; } // GET /products/:id
123
+ * async post(args: CreateProductArgs) { return created; } // POST /products
124
+ * }
125
+ *
126
+ * router.registerController(ProductController);
127
+ * ```
128
+ */
129
+ registerController<TController extends ControllerBase>(ControllerClass: new () => TController): this;
130
+ private bindControllerMethod;
131
+ private addRoute;
132
+ /**
133
+ * Build router for current runtime (Express or Bun)
134
+ * Automatically detects runtime and builds appropriate router implementation
135
+ * @returns Promise that resolves to Express Router or Bun Router
136
+ */
137
+ build(): Promise<ExpressRouter | BunRouter>;
138
+ /**
139
+ * Build router for Express runtime
140
+ * @returns Promise that resolves to Express Router
141
+ */
142
+ buildExpress(): Promise<ExpressRouter>;
143
+ /**
144
+ * Build router for Bun runtime
145
+ * @param basePath - Optional base path prefix for all routes
146
+ * @returns Promise that resolves to Bun Router
147
+ */
148
+ buildBun(basePath?: string): Promise<BunRouter>;
149
+ }
150
+ /**
151
+ * Create a new WebRouter instance
152
+ * Factory function for creating runtime-agnostic routers
153
+ * @returns New WebRouter instance
154
+ * @example
155
+ * ```typescript
156
+ * const router = createRouter();
157
+ * router.get('/health', (req, res) => res.json({ status: 'ok' }));
158
+ * router.registerController(UserController);
159
+ * ```
160
+ */
161
+ export declare const createRouter: () => WebRouter;
162
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpG;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChE,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,YAAY,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACtC,0DAA0D;IAC1D,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1G,oEAAoE;IACpE,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,UAAU,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CAAC;CAuCzD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,QAAO,SAA4B,CAAC"}
package/dist/router.js ADDED
@@ -0,0 +1,350 @@
1
+ /**
2
+ * Universal Router - Runtime-agnostic router that builds to Express or Bun natively
3
+ */
4
+ import { IS_BUN } from './runtime-detect';
5
+ /**
6
+ * Base class for controllers that provides automatic route binding
7
+ */
8
+ export class ControllerBase {
9
+ }
10
+ /**
11
+ * Parse query string args with type coercion
12
+ */
13
+ const parseQueryArgs = (query) => {
14
+ const typedQuery = {};
15
+ for (const [key, rawValue,] of Object.entries(query)) {
16
+ if (typeof rawValue !== 'string') {
17
+ typedQuery[key] = rawValue;
18
+ continue;
19
+ }
20
+ if (rawValue.length > 100) {
21
+ typedQuery[key] = rawValue;
22
+ continue;
23
+ }
24
+ if (rawValue === 'true') {
25
+ typedQuery[key] = true;
26
+ }
27
+ else if (rawValue === 'false') {
28
+ typedQuery[key] = false;
29
+ }
30
+ else {
31
+ const num = Number(rawValue);
32
+ if (!Number.isNaN(num)) {
33
+ typedQuery[key] = num;
34
+ }
35
+ else {
36
+ typedQuery[key] = rawValue;
37
+ }
38
+ }
39
+ }
40
+ return typedQuery;
41
+ };
42
+ export { BunRouter } from './bun';
43
+ /**
44
+ * Convert path pattern to regex
45
+ */
46
+ const pathToRegex = (path) => {
47
+ const paramNames = [];
48
+ const regexStr = path
49
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
50
+ .replace(/:(\w+)(\?)?/g, (_, name, optional) => {
51
+ paramNames.push(name);
52
+ return optional ? '([^/]*)?' : '([^/]+)';
53
+ })
54
+ .replace(/\*/g, '(.*)');
55
+ return {
56
+ regex: new RegExp(`^${regexStr}$`),
57
+ paramNames,
58
+ };
59
+ };
60
+ /**
61
+ * Universal Router - define routes once, build for Express or Bun
62
+ * Provides a runtime-agnostic API for defining HTTP routes and middleware
63
+ */
64
+ export class WebRouter {
65
+ routes = [];
66
+ subRouters = [];
67
+ globalMiddlewares = [];
68
+ use(pathOrMiddleware, router) {
69
+ if (typeof pathOrMiddleware === 'function') {
70
+ this.globalMiddlewares.push(pathOrMiddleware);
71
+ }
72
+ else if (router) {
73
+ this.subRouters.push({ path: pathOrMiddleware, router });
74
+ }
75
+ return this;
76
+ }
77
+ /**
78
+ * Register a GET route
79
+ * @param path - URL path (supports :param and * wildcards)
80
+ * @param handlers - Middleware and route handler functions
81
+ * @returns This router instance for chaining
82
+ */
83
+ get(path, ...handlers) {
84
+ return this.addRoute('GET', path, handlers);
85
+ }
86
+ /**
87
+ * Register a POST route
88
+ * @param path - URL path (supports :param and * wildcards)
89
+ * @param handlers - Middleware and route handler functions
90
+ * @returns This router instance for chaining
91
+ */
92
+ post(path, ...handlers) {
93
+ return this.addRoute('POST', path, handlers);
94
+ }
95
+ /**
96
+ * Register a PUT route
97
+ * @param path - URL path (supports :param and * wildcards)
98
+ * @param handlers - Middleware and route handler functions
99
+ * @returns This router instance for chaining
100
+ */
101
+ put(path, ...handlers) {
102
+ return this.addRoute('PUT', path, handlers);
103
+ }
104
+ /**
105
+ * Register a PATCH route
106
+ * @param path - URL path (supports :param and * wildcards)
107
+ * @param handlers - Middleware and route handler functions
108
+ * @returns This router instance for chaining
109
+ */
110
+ patch(path, ...handlers) {
111
+ return this.addRoute('PATCH', path, handlers);
112
+ }
113
+ /**
114
+ * Register a DELETE route
115
+ * @param path - URL path (supports :param and * wildcards)
116
+ * @param handlers - Middleware and route handler functions
117
+ * @returns This router instance for chaining
118
+ */
119
+ delete(path, ...handlers) {
120
+ return this.addRoute('DELETE', path, handlers);
121
+ }
122
+ /**
123
+ * Register a GET route with a regex pattern
124
+ * Useful for complex pattern matching (e.g., SPA routes with locale prefixes)
125
+ * @param pattern - Regular expression for matching the URL path
126
+ * @param paramNames - Names for captured groups in the regex
127
+ * @param handlers - Middleware and route handler functions
128
+ * @returns This router instance for chaining
129
+ * @example
130
+ * ```typescript
131
+ * router.getRegex(/^\/(en|sk|cs)\/products$/, ['locale'], (req, res) => {
132
+ * const locale = req.params.locale; // 'en', 'sk', or 'cs'
133
+ * });
134
+ * ```
135
+ */
136
+ getRegex(pattern, paramNames, ...handlers) {
137
+ return this.addRegexRoute('GET', pattern, paramNames, handlers);
138
+ }
139
+ addRegexRoute(method, regex, paramNames, handlers) {
140
+ // Use a special path format for regex routes
141
+ const path = `__regex__${this.routes.length}`;
142
+ this.routes.push({ method, path, regex, paramNames, handlers });
143
+ return this;
144
+ }
145
+ /**
146
+ * Register a controller class with automatic route binding
147
+ * Maps controller methods (get, post, etc.) to HTTP routes automatically
148
+ * @param ControllerClass - Controller class to register
149
+ * @returns This router instance for chaining
150
+ * @example
151
+ * ```typescript
152
+ * @Route('/products')
153
+ * class ProductController extends ControllerBase {
154
+ * async getAll() { return products; } // GET /products
155
+ * async get(args: { id: number }) { return product; } // GET /products/:id
156
+ * async post(args: CreateProductArgs) { return created; } // POST /products
157
+ * }
158
+ *
159
+ * router.registerController(ProductController);
160
+ * ```
161
+ */
162
+ registerController(ControllerClass) {
163
+ const controller = new ControllerClass();
164
+ let route = controller.$route || controller.constructor?.$route;
165
+ if (!route) {
166
+ route = ControllerClass.name.replace('Controller', '');
167
+ route = route.substring(0, 1).toLowerCase() + route.substring(1);
168
+ }
169
+ if (!route.startsWith('/')) {
170
+ route = `/${route}`;
171
+ }
172
+ this.bindControllerMethod('getAll', controller, route);
173
+ this.bindControllerMethod('get', controller, route);
174
+ this.bindControllerMethod('post', controller, route);
175
+ this.bindControllerMethod('patch', controller, route);
176
+ this.bindControllerMethod('put', controller, route);
177
+ this.bindControllerMethod('delete', controller, route);
178
+ return this;
179
+ }
180
+ bindControllerMethod(method, controller, route) {
181
+ if (!controller[method]) {
182
+ return;
183
+ }
184
+ // Get method-specific or controller-level auth
185
+ const auth = controller[`$auth-${method}`]
186
+ || (controller.constructor || {})[`$auth-${method}`]
187
+ || controller.$auth
188
+ || controller.constructor?.$auth;
189
+ // Get method-specific or default parse args
190
+ const customParseArgs = controller[`$parse-${method}`]
191
+ || (controller.constructor || {})[`$parse-${method}`];
192
+ // Get request size limit
193
+ const requestSize = controller.$requestSize
194
+ || controller.constructor?.$requestSize;
195
+ // Get controller middlewares (clone to avoid mutation)
196
+ const controllerMiddlewares = [
197
+ ...(controller.$middlewares
198
+ || controller.constructor?.$middlewares
199
+ || []),
200
+ ];
201
+ const isBodyMethod = method !== 'delete' && method !== 'get' && method !== 'getAll';
202
+ const hasGetAndGetAll = controller.get != null && controller.getAll != null;
203
+ // Build middleware chain (same order as RouteBinder)
204
+ const middlewares = [];
205
+ // 1. Auth middleware first (unshift in original = first in array)
206
+ if (auth) {
207
+ middlewares.push(async (req, res, next) => {
208
+ const authResult = await auth(req, res);
209
+ if (!authResult) {
210
+ res.status(401).send('Unauthorized access');
211
+ return;
212
+ }
213
+ next();
214
+ });
215
+ }
216
+ // 2. Controller middlewares
217
+ middlewares.push(...controllerMiddlewares);
218
+ // Main handler
219
+ const mainHandler = async (req, res, next) => {
220
+ try {
221
+ // Parse args
222
+ let args;
223
+ if (customParseArgs) {
224
+ args = customParseArgs(req);
225
+ }
226
+ else if (isBodyMethod) {
227
+ args = req.body;
228
+ }
229
+ else {
230
+ args = parseQueryArgs(req.query);
231
+ }
232
+ // Handle get vs getAll routing
233
+ let actualMethod = method;
234
+ if ((method === 'get' || method === 'getAll') && hasGetAndGetAll) {
235
+ actualMethod = args.id > 0 ? 'get' : 'getAll';
236
+ }
237
+ const result = await controller[actualMethod].call(controller, args, req, res, next);
238
+ res.json(result);
239
+ }
240
+ catch (error) {
241
+ // Only handle HTTP errors (httpCode > 299), rethrow others
242
+ if (error?.httpCode > 299) {
243
+ const httpCode = error.httpCode ?? 500;
244
+ const message = error.message ?? 'Unexpected error';
245
+ const response = { success: false, message };
246
+ // Include interception data (WorkflowInterceptionException)
247
+ if (error.interception) {
248
+ response.interception = {
249
+ type: error.interception?.type,
250
+ data: error.interception?.data,
251
+ };
252
+ }
253
+ res.status(httpCode).json(response);
254
+ return;
255
+ }
256
+ // Rethrow non-HTTP errors
257
+ throw error;
258
+ }
259
+ };
260
+ const httpMethod = method === 'getAll' ? 'GET' : method.toUpperCase();
261
+ // Store route with middlewares + main handler
262
+ // requestSize is used by Express router for body parsing
263
+ this.routes.push({
264
+ method: httpMethod,
265
+ path: route,
266
+ handlers: [
267
+ ...middlewares,
268
+ mainHandler,
269
+ ],
270
+ requestSize: isBodyMethod ? requestSize : undefined,
271
+ });
272
+ }
273
+ addRoute(method, path, handlers) {
274
+ this.routes.push({ method, path, handlers });
275
+ return this;
276
+ }
277
+ /**
278
+ * Build router for current runtime (Express or Bun)
279
+ * Automatically detects runtime and builds appropriate router implementation
280
+ * @returns Promise that resolves to Express Router or Bun Router
281
+ */
282
+ build() {
283
+ if (IS_BUN) {
284
+ return this.buildBun('');
285
+ }
286
+ return this.buildExpress();
287
+ }
288
+ /**
289
+ * Build router for Express runtime
290
+ * @returns Promise that resolves to Express Router
291
+ */
292
+ async buildExpress() {
293
+ const { buildExpressRouter } = await import('./express');
294
+ return buildExpressRouter(this.routes, this.subRouters.map(sr => ({ path: sr.path, buildExpress: () => sr.router.buildExpress() })));
295
+ }
296
+ /**
297
+ * Build router for Bun runtime
298
+ * @param basePath - Optional base path prefix for all routes
299
+ * @returns Promise that resolves to Bun Router
300
+ */
301
+ async buildBun(basePath = '') {
302
+ const { BunRouter: BunRouterImpl } = await import('./bun');
303
+ const bunRoutes = [];
304
+ // Collect sub-router routes
305
+ for (const { path, router: subRouter } of this.subRouters) {
306
+ const subBunRouter = await subRouter.buildBun(basePath + path);
307
+ bunRoutes.push(...subBunRouter.routes);
308
+ }
309
+ // Collect own routes
310
+ for (const route of this.routes) {
311
+ // Handle regex routes (path starts with __regex__)
312
+ if (route.path.startsWith('__regex__')) {
313
+ bunRoutes.push({
314
+ method: route.method,
315
+ path: route.path,
316
+ regex: route.regex,
317
+ paramNames: route.paramNames || [],
318
+ handlers: route.handlers,
319
+ globalMiddlewares: this.globalMiddlewares,
320
+ });
321
+ }
322
+ else {
323
+ const fullPath = basePath + route.path;
324
+ const { regex, paramNames } = pathToRegex(fullPath);
325
+ bunRoutes.push({
326
+ method: route.method,
327
+ path: fullPath,
328
+ regex,
329
+ paramNames,
330
+ handlers: route.handlers,
331
+ globalMiddlewares: this.globalMiddlewares,
332
+ });
333
+ }
334
+ }
335
+ return new BunRouterImpl(bunRoutes);
336
+ }
337
+ }
338
+ /**
339
+ * Create a new WebRouter instance
340
+ * Factory function for creating runtime-agnostic routers
341
+ * @returns New WebRouter instance
342
+ * @example
343
+ * ```typescript
344
+ * const router = createRouter();
345
+ * router.get('/health', (req, res) => res.json({ status: 'ok' }));
346
+ * router.registerController(UserController);
347
+ * ```
348
+ */
349
+ export const createRouter = () => new WebRouter();
350
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAkC1C;;GAEG;AACH,MAAM,OAAO,cAAc;CAA2B;AAEtD;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,KAA0B,EAAuB,EAAE;IAC1E,MAAM,UAAU,GAAwB,EAAE,CAAC;IAE3C,KAAK,MAAM,CACV,GAAG,EACH,QAAQ,EACR,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAClC,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;YAC3B,SAAS;QACV,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC3B,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;YAC3B,SAAS;QACV,CAAC;QAED,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;YACzB,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QACxB,CAAC;aAA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C;oBACd,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,KAAK,EAAE,KAAK,CAAC,KAAM;oBACnB,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,EAAE;oBAClC,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;iBACzC,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,MAAM,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC;gBACvC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAEpD,SAAS,CAAC,IAAI,CAAC;oBACd,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,IAAI,EAAE,QAAQ;oBACd,KAAK;oBACL,UAAU;oBACV,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;iBACzC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;CACD;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Runtime detection utilities for Bun/Node.js dual runtime support
3
+ */
4
+ /**
5
+ * Check if the current runtime is Bun
6
+ */
7
+ export declare const isBunRuntime: () => boolean;
8
+ /**
9
+ * Get the current runtime name
10
+ */
11
+ export declare const getRuntime: () => "bun" | "node";
12
+ /**
13
+ * Cached runtime detection result (computed once at module load)
14
+ */
15
+ export declare const RUNTIME: "bun" | "node";
16
+ /**
17
+ * Cached Bun runtime check (computed once at module load)
18
+ */
19
+ export declare const IS_BUN: boolean;
20
+ //# sourceMappingURL=runtime-detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-detect.d.ts","sourceRoot":"","sources":["../src/runtime-detect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,YAAY,QAAO,OAAyD,CAAC;AAE1F;;GAEG;AACH,eAAO,MAAM,UAAU,QAAO,KAAK,GAAG,MAAyC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,OAAO,gBAAe,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,MAAM,SAAiB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Runtime detection utilities for Bun/Node.js dual runtime support
3
+ */
4
+ /**
5
+ * Check if the current runtime is Bun
6
+ */
7
+ export const isBunRuntime = () => typeof globalThis.Bun !== 'undefined';
8
+ /**
9
+ * Get the current runtime name
10
+ */
11
+ export const getRuntime = () => isBunRuntime() ? 'bun' : 'node';
12
+ /**
13
+ * Cached runtime detection result (computed once at module load)
14
+ */
15
+ export const RUNTIME = getRuntime();
16
+ /**
17
+ * Cached Bun runtime check (computed once at module load)
18
+ */
19
+ export const IS_BUN = isBunRuntime();
20
+ //# sourceMappingURL=runtime-detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-detect.js","sourceRoot":"","sources":["../src/runtime-detect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAY,EAAE,CAAC,OAAQ,UAAkB,CAAC,GAAG,KAAK,WAAW,CAAC;AAE1F;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAmB,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC"}