@stacksjs/bun-router 0.0.5 → 0.0.7

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 (269) hide show
  1. package/dist/auth.d.ts +134 -0
  2. package/dist/cache/lru-cache.d.ts +139 -0
  3. package/dist/cache/middleware-memoization.d.ts +151 -0
  4. package/dist/cache/route-cache-warmer.d.ts +161 -0
  5. package/dist/cache/sqlite-cache.d.ts +209 -0
  6. package/dist/cache/streaming-cache.d.ts +132 -0
  7. package/dist/cli/colors.d.ts +15 -0
  8. package/dist/cli/index.d.ts +10 -0
  9. package/dist/cli/middleware.d.ts +31 -0
  10. package/dist/cli/openapi.d.ts +17 -0
  11. package/dist/cli/router.d.ts +15 -0
  12. package/dist/cli/routes.d.ts +29 -0
  13. package/dist/cli/utils.d.ts +74 -0
  14. package/dist/cli.d.ts +1 -1
  15. package/dist/cli.js +1 -1
  16. package/dist/config.d.ts +7 -0
  17. package/dist/container/container.d.ts +273 -0
  18. package/dist/container/contextual-binding.d.ts +240 -0
  19. package/dist/container/decorators.d.ts +141 -0
  20. package/dist/container/service-provider.d.ts +285 -0
  21. package/dist/development/hot-reload.d.ts +187 -0
  22. package/dist/development/index.d.ts +167 -0
  23. package/dist/development/performance-profiler.d.ts +217 -0
  24. package/dist/development/route-debugger.d.ts +154 -0
  25. package/dist/development/route-inspector.d.ts +211 -0
  26. package/dist/development/typescript-utilities.d.ts +209 -0
  27. package/dist/docs.d.ts +11 -0
  28. package/dist/errors/circuit-breaker.d.ts +195 -0
  29. package/dist/errors/error-handler.d.ts +88 -0
  30. package/dist/errors/error-reporting.d.ts +144 -0
  31. package/dist/errors/exceptions.d.ts +184 -0
  32. package/dist/errors/graceful-degradation.d.ts +154 -0
  33. package/dist/errors/index.d.ts +9 -0
  34. package/dist/errors/router-errors.d.ts +110 -0
  35. package/dist/file-serving/static-files.d.ts +143 -0
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.js +375 -227
  38. package/dist/middleware/auth.d.ts +63 -0
  39. package/dist/middleware/content_security_policy.d.ts +53 -0
  40. package/dist/middleware/cors.d.ts +5 -0
  41. package/dist/middleware/csrf.d.ts +7 -0
  42. package/dist/middleware/ddos_protection.d.ts +39 -0
  43. package/dist/middleware/file_security.d.ts +26 -0
  44. package/dist/middleware/file_upload.d.ts +38 -0
  45. package/dist/middleware/helmet.d.ts +54 -0
  46. package/dist/middleware/index.d.ts +44 -0
  47. package/dist/middleware/input_validation.d.ts +45 -0
  48. package/dist/middleware/json_body.d.ts +4 -0
  49. package/dist/middleware/performance_alerting.d.ts +87 -0
  50. package/dist/middleware/performance_dashboard.d.ts +87 -0
  51. package/dist/middleware/performance_monitor.d.ts +209 -0
  52. package/dist/middleware/pipeline.d.ts +131 -0
  53. package/dist/middleware/rate_limit.d.ts +36 -0
  54. package/dist/middleware/request_id.d.ts +4 -0
  55. package/dist/middleware/request_signing.d.ts +153 -0
  56. package/dist/middleware/request_tracer.d.ts +72 -0
  57. package/dist/middleware/response_cache.d.ts +97 -0
  58. package/dist/middleware/security.d.ts +69 -0
  59. package/dist/middleware/security_suite.d.ts +46 -0
  60. package/dist/middleware/session.d.ts +23 -0
  61. package/dist/model-binding/index.d.ts +2 -0
  62. package/dist/model-binding/model-middleware.d.ts +118 -0
  63. package/dist/model-binding/model-registry.d.ts +164 -0
  64. package/dist/model-binding.d.ts +185 -0
  65. package/dist/model-resolver-factory.d.ts +31 -0
  66. package/dist/observability/correlation.d.ts +187 -0
  67. package/dist/observability/health-checks.d.ts +186 -0
  68. package/dist/observability/index.d.ts +60 -0
  69. package/dist/observability/integration.d.ts +147 -0
  70. package/dist/observability/metrics.d.ts +184 -0
  71. package/dist/observability/tracing.d.ts +187 -0
  72. package/dist/optimization/bun-utilities.d.ts +224 -0
  73. package/dist/query-builder-integration.d.ts +36 -0
  74. package/dist/request/context.d.ts +34 -0
  75. package/dist/request/enhanced-request.d.ts +213 -0
  76. package/dist/request/macros.d.ts +300 -0
  77. package/dist/response/macros.d.ts +245 -0
  78. package/dist/response/response-factory.d.ts +133 -0
  79. package/dist/router/api-routes.d.ts +5 -0
  80. package/dist/router/file-based-routing.d.ts +118 -0
  81. package/dist/router/file-streaming.d.ts +5 -0
  82. package/dist/router/fluent-router.d.ts +315 -0
  83. package/dist/router/fluent-routing.d.ts +271 -0
  84. package/dist/router/group-organization.d.ts +5 -0
  85. package/dist/router/handler-resolver.d.ts +24 -0
  86. package/dist/router/http-methods.d.ts +10 -0
  87. package/dist/router/index.d.ts +113 -0
  88. package/dist/router/middleware-groups.d.ts +94 -0
  89. package/dist/router/middleware-integration.d.ts +112 -0
  90. package/dist/router/middleware.d.ts +5 -0
  91. package/dist/router/model-binding.d.ts +5 -0
  92. package/dist/router/optimized-route-matching.d.ts +6 -0
  93. package/dist/router/route-building.d.ts +5 -0
  94. package/dist/router/route-compiler.d.ts +153 -0
  95. package/dist/router/route-matching.d.ts +5 -0
  96. package/dist/router/route-trie.d.ts +114 -0
  97. package/dist/router/router.d.ts +276 -0
  98. package/dist/router/server.d.ts +5 -0
  99. package/dist/router/validation-integration.d.ts +170 -0
  100. package/dist/router/view-rendering.d.ts +5 -0
  101. package/dist/router/websocket.d.ts +5 -0
  102. package/dist/routing/route-caching.d.ts +129 -0
  103. package/dist/routing/route-throttling.d.ts +150 -0
  104. package/dist/routing/subdomain-routing.d.ts +206 -0
  105. package/dist/session/database-store.d.ts +51 -0
  106. package/dist/session/file-store.d.ts +22 -0
  107. package/dist/session/index.d.ts +106 -0
  108. package/dist/session/memory-store.d.ts +21 -0
  109. package/dist/session/redis-store.d.ts +31 -0
  110. package/dist/streaming/index.d.ts +3 -0
  111. package/dist/streaming/sse-handler.d.ts +138 -0
  112. package/dist/streaming/stream-handler.d.ts +114 -0
  113. package/dist/testing/auth-testing.d.ts +156 -0
  114. package/dist/testing/file-upload-testing.d.ts +190 -0
  115. package/dist/testing/index.d.ts +10 -0
  116. package/dist/testing/middleware-testing.d.ts +138 -0
  117. package/dist/testing/model-binding-testing.d.ts +186 -0
  118. package/dist/testing/performance-testing.d.ts +235 -0
  119. package/dist/testing/test-client.d.ts +117 -0
  120. package/dist/testing/test-request.d.ts +85 -0
  121. package/dist/testing/test-response.d.ts +90 -0
  122. package/dist/testing/types.d.ts +207 -0
  123. package/dist/testing/websocket-testing.d.ts +227 -0
  124. package/dist/types/controller-types.d.ts +208 -0
  125. package/dist/types/core.d.ts +543 -0
  126. package/dist/types/middleware-types.d.ts +227 -0
  127. package/dist/types/request-response-augmentation.d.ts +261 -0
  128. package/dist/types/route-inference.d.ts +168 -0
  129. package/dist/types.d.ts +1776 -0
  130. package/dist/url.d.ts +56 -0
  131. package/dist/utils/index.d.ts +1 -0
  132. package/dist/utils/query-preservation.d.ts +48 -0
  133. package/dist/utils.d.ts +69 -0
  134. package/dist/validation/validator.d.ts +140 -0
  135. package/dist/websocket/clustering.d.ts +185 -0
  136. package/package.json +3 -2
  137. package/src/auth.ts +469 -0
  138. package/src/cache/lru-cache.ts +457 -0
  139. package/src/cache/middleware-memoization.ts +531 -0
  140. package/src/cache/route-cache-warmer.ts +486 -0
  141. package/src/cache/sqlite-cache.ts +783 -0
  142. package/src/cache/streaming-cache.ts +572 -0
  143. package/src/cli/colors.ts +29 -0
  144. package/src/cli/index.ts +287 -0
  145. package/src/cli/middleware.ts +291 -0
  146. package/src/cli/openapi.ts +407 -0
  147. package/src/cli/router.ts +188 -0
  148. package/src/cli/routes.ts +265 -0
  149. package/src/cli/utils.ts +531 -0
  150. package/src/cli.ts +5 -0
  151. package/src/config.ts +322 -0
  152. package/src/container/container.ts +740 -0
  153. package/src/container/contextual-binding.ts +603 -0
  154. package/src/container/decorators.ts +359 -0
  155. package/src/container/service-provider.ts +596 -0
  156. package/src/development/hot-reload.ts +673 -0
  157. package/src/development/index.ts +499 -0
  158. package/src/development/performance-profiler.ts +717 -0
  159. package/src/development/route-debugger.ts +527 -0
  160. package/src/development/route-inspector.ts +749 -0
  161. package/src/development/typescript-utilities.ts +678 -0
  162. package/src/docs.ts +397 -0
  163. package/src/errors/circuit-breaker.ts +732 -0
  164. package/src/errors/error-handler.ts +569 -0
  165. package/src/errors/error-reporting.ts +672 -0
  166. package/src/errors/exceptions.ts +536 -0
  167. package/src/errors/graceful-degradation.ts +621 -0
  168. package/src/errors/index.ts +21 -0
  169. package/src/errors/router-errors.ts +632 -0
  170. package/src/file-serving/static-files.ts +581 -0
  171. package/src/index.ts +14 -0
  172. package/src/middleware/auth.ts +219 -0
  173. package/src/middleware/content_security_policy.ts +215 -0
  174. package/src/middleware/cors.ts +74 -0
  175. package/src/middleware/csrf.ts +108 -0
  176. package/src/middleware/ddos_protection.ts +255 -0
  177. package/src/middleware/file_security.ts +191 -0
  178. package/src/middleware/file_upload.ts +264 -0
  179. package/src/middleware/helmet.ts +268 -0
  180. package/src/middleware/index.ts +117 -0
  181. package/src/middleware/input_validation.ts +449 -0
  182. package/src/middleware/json_body.ts +37 -0
  183. package/src/middleware/performance_alerting.ts +538 -0
  184. package/src/middleware/performance_dashboard.ts +661 -0
  185. package/src/middleware/performance_monitor.ts +943 -0
  186. package/src/middleware/pipeline.ts +489 -0
  187. package/src/middleware/rate_limit.ts +245 -0
  188. package/src/middleware/request_id.ts +36 -0
  189. package/src/middleware/request_signing.ts +636 -0
  190. package/src/middleware/request_tracer.ts +636 -0
  191. package/src/middleware/response_cache.ts +743 -0
  192. package/src/middleware/security.ts +482 -0
  193. package/src/middleware/security_suite.ts +257 -0
  194. package/src/middleware/session.ts +91 -0
  195. package/src/model-binding/index.ts +18 -0
  196. package/src/model-binding/model-middleware.ts +425 -0
  197. package/src/model-binding/model-registry.ts +550 -0
  198. package/src/model-binding.ts +370 -0
  199. package/src/model-resolver-factory.ts +106 -0
  200. package/src/observability/correlation.ts +691 -0
  201. package/src/observability/health-checks.ts +729 -0
  202. package/src/observability/index.ts +184 -0
  203. package/src/observability/integration.ts +548 -0
  204. package/src/observability/metrics.ts +753 -0
  205. package/src/observability/tracing.ts +638 -0
  206. package/src/optimization/bun-utilities.ts +778 -0
  207. package/src/query-builder-integration.ts +137 -0
  208. package/src/request/context.ts +62 -0
  209. package/src/request/enhanced-request.ts +857 -0
  210. package/src/request/macros.ts +688 -0
  211. package/src/response/macros.ts +612 -0
  212. package/src/response/response-factory.ts +588 -0
  213. package/src/router/api-routes.ts +243 -0
  214. package/src/router/file-based-routing.ts +670 -0
  215. package/src/router/file-streaming.ts +372 -0
  216. package/src/router/fluent-router.ts +927 -0
  217. package/src/router/fluent-routing.ts +797 -0
  218. package/src/router/group-organization.ts +213 -0
  219. package/src/router/handler-resolver.ts +291 -0
  220. package/src/router/http-methods.ts +377 -0
  221. package/src/router/index.ts +185 -0
  222. package/src/router/middleware-groups.ts +222 -0
  223. package/src/router/middleware-integration.ts +399 -0
  224. package/src/router/middleware.ts +231 -0
  225. package/src/router/model-binding.ts +215 -0
  226. package/src/router/optimized-route-matching.ts +253 -0
  227. package/src/router/route-building.ts +212 -0
  228. package/src/router/route-compiler.ts +702 -0
  229. package/src/router/route-matching.ts +349 -0
  230. package/src/router/route-trie.ts +464 -0
  231. package/src/router/router.ts +1524 -0
  232. package/src/router/server.ts +429 -0
  233. package/src/router/validation-integration.ts +443 -0
  234. package/src/router/view-rendering.ts +233 -0
  235. package/src/router/websocket.ts +100 -0
  236. package/src/routing/route-caching.ts +402 -0
  237. package/src/routing/route-throttling.ts +469 -0
  238. package/src/routing/subdomain-routing.ts +492 -0
  239. package/src/session/database-store.ts +109 -0
  240. package/src/session/file-store.ts +148 -0
  241. package/src/session/index.ts +244 -0
  242. package/src/session/memory-store.ts +88 -0
  243. package/src/session/redis-store.ts +93 -0
  244. package/src/streaming/index.ts +17 -0
  245. package/src/streaming/sse-handler.ts +482 -0
  246. package/src/streaming/stream-handler.ts +552 -0
  247. package/src/testing/auth-testing.ts +446 -0
  248. package/src/testing/file-upload-testing.ts +543 -0
  249. package/src/testing/index.ts +10 -0
  250. package/src/testing/middleware-testing.ts +322 -0
  251. package/src/testing/model-binding-testing.ts +645 -0
  252. package/src/testing/performance-testing.ts +738 -0
  253. package/src/testing/test-client.ts +310 -0
  254. package/src/testing/test-request.ts +315 -0
  255. package/src/testing/test-response.ts +332 -0
  256. package/src/testing/types.ts +224 -0
  257. package/src/testing/websocket-testing.ts +590 -0
  258. package/src/types/controller-types.ts +385 -0
  259. package/src/types/core.ts +683 -0
  260. package/src/types/middleware-types.ts +419 -0
  261. package/src/types/request-response-augmentation.ts +489 -0
  262. package/src/types/route-inference.ts +357 -0
  263. package/src/types.ts +2049 -0
  264. package/src/url.ts +126 -0
  265. package/src/utils/index.ts +1 -0
  266. package/src/utils/query-preservation.ts +201 -0
  267. package/src/utils.ts +327 -0
  268. package/src/validation/validator.ts +685 -0
  269. package/src/websocket/clustering.ts +762 -0
@@ -0,0 +1,113 @@
1
+ import type { ActionHandler, Route } from '../types';
2
+ import { Dependencies, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, SkipConditions } from '../middleware/pipeline';
3
+ import { FluentRouteBuilder, FluentRouter, RouteFactory, router, RouterUtils } from './fluent-routing';
4
+ import { Router } from './router';
5
+ import '../types';
6
+ export { Router };
7
+ declare module './router' {
8
+ interface Router {
9
+ stream: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, status?: number, headers?: Record<string, string>) => Response;
10
+ streamJson: <T>(data: Record<string, Iterable<T> | AsyncIterable<T>>, status?: number, headers?: Record<string, string>) => Response;
11
+ eventStream: <_T = any>(callback: () => Generator<{
12
+ data: any;
13
+ event?: string;
14
+ id?: string;
15
+ retry?: number;
16
+ }, void, unknown> | AsyncGenerator<{
17
+ data: any;
18
+ event?: string;
19
+ id?: string;
20
+ retry?: number;
21
+ }, void, unknown>, headers?: Record<string, string>) => Response;
22
+ streamDownload: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, filename: string, headers?: Record<string, string>) => Response;
23
+ streamFile: (filePath: string, request: any, options?: {
24
+ contentType?: string;
25
+ enableRanges?: boolean;
26
+ chunkSize?: number;
27
+ }) => Promise<Response>;
28
+ streamFileWithRanges: (filePath: string, req: any) => Promise<Response>;
29
+ streamResponse: (generator: () => AsyncGenerator<string | Uint8Array, void, unknown>, options?: {
30
+ headers?: Record<string, string>;
31
+ status?: number;
32
+ }) => Response;
33
+ transformStream: (transformer: (chunk: string | Uint8Array) => string | Uint8Array | Promise<string | Uint8Array>, options?: {
34
+ headers?: Record<string, string>;
35
+ status?: number;
36
+ }) => (req: Request) => Response;
37
+ model: <T>(key: string, modelClass: string | ((_value: string) => Promise<T | null>), callback?: (model: T | null) => Response | null) => Router;
38
+ implicitBinding: () => any;
39
+ missing: (callback: (req: any) => Response) => any;
40
+ scopedBindings: (bindings: Record<string, string>) => any;
41
+ clearModelCache: (modelName?: string) => Router;
42
+ getModelStats: () => {
43
+ totalEntries: number;
44
+ validEntries: number;
45
+ expiredEntries: number;
46
+ models: number;
47
+ };
48
+ readonly modelRegistry: {
49
+ has: (name: string) => boolean;
50
+ register: <_T>(name: string, config: any) => void;
51
+ resolve: <_T>(modelName: string, params: Record<string, string>, req?: any) => Promise<any>;
52
+ createErrorResponse: (modelName: string, result: any, params: Record<string, string>) => Response;
53
+ clearCache: (modelName: string, params?: Record<string, string>) => void;
54
+ clearAllCache: () => void;
55
+ getCacheStats: () => any;
56
+ };
57
+ matchRoute: (path: string, method: string, domain?: string) => {
58
+ route: Route;
59
+ params: Record<string, string>;
60
+ } | undefined;
61
+ getAllowedMethods: (path: string, domain?: string) => string[];
62
+ clearRouteCache: () => void;
63
+ getCacheStats: () => any;
64
+ getRouteStats: () => any;
65
+ warmRouteCache: (commonPaths: Array<{
66
+ path: string;
67
+ method: string;
68
+ }>) => void;
69
+ getRoutesByMethod: () => any;
70
+ getRouteConflicts: () => any;
71
+ rebuildRouteCompiler: () => void;
72
+ optimizeRoutes: (usageStats?: Record<string, number>) => void;
73
+ addRouteToCompiler: (route: Route) => void;
74
+ initializeRouteCompiler: () => void;
75
+ health: () => Router;
76
+ renderView: (view: string, data?: Record<string, any>, options?: {
77
+ layout?: string;
78
+ }) => Promise<string>;
79
+ view: (path: string, view: string, data?: Record<string, any>, options?: {
80
+ layout?: string;
81
+ status?: number;
82
+ headers?: Record<string, string>;
83
+ }) => Router;
84
+ where: ((_param: string, _pattern: string | RegExp) => Router) & ((constraints: Record<string, string | RegExp>) => Router);
85
+ whereNumber: (param: string) => Router;
86
+ whereAlpha: (param: string) => Router;
87
+ whereAlphaNumeric: (param: string) => Router;
88
+ whereUuid: (param: string) => Router;
89
+ whereIn: (param: string, values: string[]) => Router;
90
+ domain: (domain: string, callback: () => void) => Router;
91
+ resource: (name: string, handlers: {
92
+ index?: ActionHandler;
93
+ show?: ActionHandler;
94
+ store?: ActionHandler;
95
+ update?: ActionHandler;
96
+ destroy?: ActionHandler;
97
+ create?: ActionHandler;
98
+ edit?: ActionHandler;
99
+ }) => Router;
100
+ onError: (handler: (error: Error) => Response | Promise<Response>) => Router;
101
+ redirect: (url: string, status?: 301 | 302 | 303 | 307 | 308) => Response;
102
+ permanentRedirect: (url: string) => Response;
103
+ fallback: (handler: ActionHandler) => Router;
104
+ route: (name: string, params?: Record<string, string>) => string;
105
+ }
106
+ }
107
+ export { Dependencies, FluentRouteBuilder, FluentRouter, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, RouteFactory, router, RouterUtils, SkipConditions };
108
+ export * from '../routing/route-caching';
109
+ export * from '../routing/route-throttling';
110
+ export * from '../routing/subdomain-routing';
111
+ export { createHandlerResolver, resolveHandler, wrapResponse } from './handler-resolver';
112
+ export * from './validation-integration';
113
+ export type { DiscoveredRoute, FileBasedRoutingConfig } from './file-based-routing';
@@ -0,0 +1,94 @@
1
+ import type { MiddlewareHandler } from '../types';
2
+ /**
3
+ * Middleware Group Registry
4
+ *
5
+ * Allows defining named groups of middleware that can be applied to routes.
6
+ * Similar to Laravel's middleware groups (web, api).
7
+ *
8
+ * @example
9
+ * // Define groups
10
+ * groups.define('web', ['session', 'csrf', 'cors'])
11
+ * groups.define('api', ['throttle:60,1', 'cors'])
12
+ *
13
+ * // Use on routes
14
+ * router.group({ middleware: 'web' }, () => { ... })
15
+ */
16
+ export declare class MiddlewareGroupRegistry {
17
+ private groups;
18
+ private globalMiddleware;
19
+ private middlewarePriority;
20
+ /**
21
+ * Define a middleware group
22
+ */
23
+ define(name: string, middleware: (string | MiddlewareHandler)[]): this;
24
+ /**
25
+ * Extend an existing group with additional middleware
26
+ */
27
+ extend(name: string, middleware: (string | MiddlewareHandler)[]): this;
28
+ /**
29
+ * Prepend middleware to an existing group
30
+ */
31
+ prepend(name: string, middleware: (string | MiddlewareHandler)[]): this;
32
+ /**
33
+ * Get middleware for a group
34
+ */
35
+ get(name: string): (string | MiddlewareHandler)[];
36
+ /**
37
+ * Check if a group exists
38
+ */
39
+ has(name: string): boolean;
40
+ /**
41
+ * Remove a group
42
+ */
43
+ remove(name: string): this;
44
+ /**
45
+ * Resolve a middleware reference, expanding group names into their middleware
46
+ */
47
+ resolve(middleware: string | MiddlewareHandler): (string | MiddlewareHandler)[];
48
+ /**
49
+ * Resolve multiple middleware references, expanding groups
50
+ */
51
+ resolveAll(middleware: (string | MiddlewareHandler)[]): (string | MiddlewareHandler)[];
52
+ /**
53
+ * Add middleware to the global stack (runs on every request)
54
+ */
55
+ pushGlobal(...middleware: (string | MiddlewareHandler)[]): this;
56
+ /**
57
+ * Prepend middleware to the global stack
58
+ */
59
+ prependGlobal(...middleware: (string | MiddlewareHandler)[]): this;
60
+ /**
61
+ * Remove middleware from the global stack
62
+ */
63
+ removeGlobal(middleware: string): this;
64
+ /**
65
+ * Get the global middleware stack
66
+ */
67
+ getGlobal(): (string | MiddlewareHandler)[];
68
+ /**
69
+ * Set execution priority for a middleware (lower = runs first)
70
+ */
71
+ setPriority(name: string, priority: number): this;
72
+ /**
73
+ * Sort middleware by priority
74
+ */
75
+ sortByPriority(middleware: (string | MiddlewareHandler)[]): (string | MiddlewareHandler)[];
76
+ /**
77
+ * Filter middleware by applying except/only rules.
78
+ *
79
+ * @param middleware - Full middleware list
80
+ * @param options - except or only filter
81
+ */
82
+ filter(middleware: (string | MiddlewareHandler)[], options: {
83
+ except?: string[];
84
+ only?: string[];
85
+ }): (string | MiddlewareHandler)[];
86
+ /**
87
+ * Clear all groups and global middleware
88
+ */
89
+ flush(): void;
90
+ }
91
+ /**
92
+ * Default middleware group registry instance
93
+ */
94
+ export declare const middlewareGroups: MiddlewareGroupRegistry;
@@ -0,0 +1,112 @@
1
+ import type { EnhancedRequest, MiddlewareHandler } from '../types';
2
+ import type { Router } from './router';
3
+ export type SkipConditionFn = (_req: EnhancedRequest) => boolean;
4
+ export type SkipConditionsList = SkipConditionFn[];
5
+ /**
6
+ * Skip condition helpers
7
+ */
8
+ export declare const SkipConditions: {
9
+ skipForPaths: (paths: string[]) => SkipConditionFn;
10
+ skipForMethods: (methods: string[]) => SkipConditionFn;
11
+ };
12
+ /**
13
+ * Dependency helpers
14
+ */
15
+ export declare const Dependencies: {
16
+ cache: (config: {
17
+ type: string;
18
+ ttl: number;
19
+ }) => {
20
+ type: string;
21
+ config: {
22
+ type: string;
23
+ ttl: number;
24
+ };
25
+ };
26
+ logger: (level: string) => {
27
+ type: string;
28
+ config: {
29
+ level: string;
30
+ };
31
+ };
32
+ };
33
+ declare class MiddlewarePipeline {
34
+ registerDependency(_key: string, _dependency: any): this;
35
+ registerSkipConditions(_middleware: MiddlewareHandler, _conditions: SkipConditionsList): void;
36
+ getStats(): any;
37
+ getCacheInfo(): any;
38
+ clearCache(): this;
39
+ compilePipeline(_key: string, _middleware: MiddlewareHandler[], _options?: any): void;
40
+ execute(_key: string, _req: EnhancedRequest, _handler: () => Promise<Response>): Promise<Response>;
41
+ }
42
+ /**
43
+ * Integration layer for middleware pipeline with the router
44
+ */
45
+ export declare function registerMiddlewarePipeline(RouterClass: typeof Router): void;
46
+ /**
47
+ * Middleware factory for common use cases
48
+ */
49
+ export declare class MiddlewareFactory {
50
+ private pipeline;
51
+ constructor(pipeline: MiddlewarePipeline);
52
+ /**
53
+ * Create authentication middleware with conditional execution
54
+ */
55
+ createAuthMiddleware(options?: {
56
+ skipPaths?: string[];
57
+ skipMethods?: string[];
58
+ requireRoles?: string[];
59
+ jwtSecret?: string;
60
+ }): MiddlewareHandler;
61
+ /**
62
+ * Create rate limiting middleware with dependency injection
63
+ */
64
+ createRateLimitMiddleware(options: {
65
+ maxRequests: number;
66
+ windowMs: number;
67
+ skipPaths?: string[];
68
+ }): MiddlewareHandler;
69
+ /**
70
+ * Create logging middleware with dependency injection
71
+ */
72
+ createLoggingMiddleware(options?: {
73
+ level?: string;
74
+ skipPaths?: string[];
75
+ includeBody?: boolean;
76
+ }): MiddlewareHandler;
77
+ /**
78
+ * Create CORS middleware with conditional execution
79
+ */
80
+ createCorsMiddleware(options?: {
81
+ origin?: string | string[];
82
+ methods?: string[];
83
+ allowedHeaders?: string[];
84
+ credentials?: boolean;
85
+ }): MiddlewareHandler;
86
+ }
87
+ /**
88
+ * Helper function to setup common middleware stack
89
+ */
90
+ export declare function setupMiddlewareStack(router: any, options?: {
91
+ auth?: {
92
+ jwtSecret: string;
93
+ skipPaths?: string[];
94
+ requireRoles?: string[];
95
+ };
96
+ rateLimit?: {
97
+ maxRequests: number;
98
+ windowMs: number;
99
+ skipPaths?: string[];
100
+ };
101
+ cors?: {
102
+ origin?: string | string[];
103
+ methods?: string[];
104
+ allowedHeaders?: string[];
105
+ credentials?: boolean;
106
+ };
107
+ logging?: {
108
+ level?: string;
109
+ skipPaths?: string[];
110
+ };
111
+ }): MiddlewareHandler[];
112
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Router } from './router';
2
+ /**
3
+ * Middleware handling extension for Router class
4
+ */
5
+ export declare function registerMiddlewareHandling(RouterClass: typeof Router): void;
@@ -0,0 +1,5 @@
1
+ import type { Router } from './router';
2
+ /**
3
+ * Model binding extension for Router class
4
+ */
5
+ export declare function registerModelBinding(RouterClass: typeof Router): void;
@@ -0,0 +1,6 @@
1
+ import type { Router } from './router';
2
+ /**
3
+ * Optimized route matching extension for Router class
4
+ * Replaces the original route matching with high-performance trie-based matching
5
+ */
6
+ export declare function registerOptimizedRouteMatching(RouterClass: typeof Router): void;
@@ -0,0 +1,5 @@
1
+ import type { Router } from './router';
2
+ /**
3
+ * Route building extension for Router class
4
+ */
5
+ export declare function registerRouteBuilding(RouterClass: typeof Router): void;
@@ -0,0 +1,153 @@
1
+ import type { HTTPMethod, MatchResult, Route } from '../types';
2
+ import type { CompiledRoute } from './route-trie';
3
+ /**
4
+ * Route compilation options
5
+ */
6
+ export interface RouteCompilerOptions {
7
+ enableCaching: boolean;
8
+ enableMethodGrouping: boolean;
9
+ enablePriorityOptimization: boolean;
10
+ cacheSize: number;
11
+ precompilePatterns: boolean;
12
+ }
13
+ /**
14
+ * Route matching statistics for performance monitoring
15
+ */
16
+ export interface RouteMatchStats {
17
+ totalMatches: number;
18
+ cacheHits: number;
19
+ cacheMisses: number;
20
+ averageMatchTime: number;
21
+ trieDepth: number;
22
+ methodDistribution: Record<string, number>;
23
+ }
24
+ /**
25
+ * High-performance route compiler with pre-compilation and optimization
26
+ */
27
+ export declare class RouteCompiler {
28
+ private trie;
29
+ private matchCache;
30
+ private cacheKeys;
31
+ private stats;
32
+ private options;
33
+ constructor(options?: Partial<RouteCompilerOptions>);
34
+ /**
35
+ * Add a route to the compiler
36
+ * @returns true if route was added, false if it's a duplicate
37
+ */
38
+ addRoute(route: Route): boolean;
39
+ /**
40
+ * Check if a route is an exact duplicate of an existing route
41
+ */
42
+ private checkForDuplicateRoute;
43
+ /**
44
+ * Pre-compile route patterns for faster matching
45
+ */
46
+ private patternCache;
47
+ /**
48
+ * Extract parameter names from a route path
49
+ */
50
+ private extractParamNames;
51
+ /**
52
+ * Pre-compile route patterns for faster matching
53
+ */
54
+ private precompileRoutePattern;
55
+ /**
56
+ * Convert Laravel-style route to a simple regex pattern
57
+ * @param path The route path with Laravel-style parameters
58
+ * @param constraints Optional constraints for route parameters
59
+ */
60
+ private convertToURLPattern;
61
+ /**
62
+ * Match a request path and method to a route
63
+ */
64
+ match(path: string, method: HTTPMethod): MatchResult | null;
65
+ /**
66
+ * Add an entry to the cache with LRU eviction if needed
67
+ */
68
+ private addToCache;
69
+ /**
70
+ * Update LRU tracking for a cache key
71
+ */
72
+ private updateCacheLRU;
73
+ /**
74
+ * Update average match time statistics
75
+ */
76
+ private updateMatchTime;
77
+ /**
78
+ * Get all compiled routes sorted by priority
79
+ */
80
+ getCompiledRoutes(): CompiledRoute[];
81
+ /**
82
+ * Get routes grouped by HTTP method
83
+ */
84
+ getRoutesByMethod(): Map<HTTPMethod, CompiledRoute[]>;
85
+ /**
86
+ * Warm up the cache with common routes
87
+ * @param commonPaths Array of paths and methods to pre-cache
88
+ * @param options Optional warming options
89
+ * @param options.force If true, enables caching temporarily even if disabled in compiler options
90
+ * @param options.precompile If true, performs a second match to ensure cache hits are recorded
91
+ * @returns Statistics about the warming operation
92
+ */
93
+ warmCache(commonPaths: Array<{
94
+ path: string;
95
+ method: HTTPMethod;
96
+ }>, options?: {
97
+ force?: boolean;
98
+ precompile?: boolean;
99
+ }): {
100
+ warmedPaths: number;
101
+ cacheSize: number;
102
+ hitRate: number;
103
+ };
104
+ /**
105
+ * Clear all caches and reset statistics
106
+ */
107
+ clear(): void;
108
+ /**
109
+ * Get performance statistics
110
+ */
111
+ getStats(): RouteMatchStats;
112
+ /**
113
+ * Get cache statistics
114
+ */
115
+ getCacheStats(): {
116
+ size: number;
117
+ maxSize: number;
118
+ hitRate: number;
119
+ enabled: boolean;
120
+ };
121
+ /**
122
+ * Optimize route order based on usage patterns
123
+ */
124
+ optimizeRouteOrder(_usageStats: Record<string, number>): void;
125
+ /**
126
+ * Get route conflicts (overlapping patterns)
127
+ */
128
+ getRouteConflicts(): Array<{
129
+ routes: CompiledRoute[];
130
+ conflictType: 'overlap' | 'duplicate' | 'ambiguous';
131
+ severity: 'low' | 'medium' | 'high';
132
+ }>;
133
+ /**
134
+ * Check if two routes conflict
135
+ */
136
+ private routesConflict;
137
+ /**
138
+ * Check if two route patterns overlap
139
+ */
140
+ private patternsOverlap;
141
+ /**
142
+ * Get conflict severity
143
+ */
144
+ private getConflictSeverity;
145
+ /**
146
+ * Get conflict type
147
+ */
148
+ private getConflictType;
149
+ /**
150
+ * Check if routes have ambiguous parameters
151
+ */
152
+ private hasAmbiguousParameters;
153
+ }
@@ -0,0 +1,5 @@
1
+ import type { Router } from './router';
2
+ /**
3
+ * Route matching extension for Router class
4
+ */
5
+ export declare function registerRouteMatching(RouterClass: typeof Router): void;
@@ -0,0 +1,114 @@
1
+ import type { HTTPMethod, Route } from '../types';
2
+ /**
3
+ * Route segment types for the trie
4
+ */
5
+ export type RouteSegmentType = 'static' | 'parameter' | 'wildcard' | 'optional';
6
+ export interface RouteSegment {
7
+ type: RouteSegmentType;
8
+ value: string;
9
+ paramName?: string;
10
+ pattern?: RegExp;
11
+ optional?: boolean;
12
+ }
13
+ export interface CompiledRoute {
14
+ route: Route;
15
+ segments: RouteSegment[];
16
+ paramNames: string[];
17
+ priority: number;
18
+ staticScore: number;
19
+ dynamicScore: number;
20
+ }
21
+ /**
22
+ * Trie node for efficient route matching
23
+ */
24
+ export declare class TrieNode {
25
+ children: Map<string, TrieNode>;
26
+ paramChild: TrieNode | null;
27
+ wildcardChild: TrieNode | null;
28
+ routes: Map<HTTPMethod, CompiledRoute>;
29
+ paramName: string | null;
30
+ pattern: RegExp | null;
31
+ isEndpoint: boolean;
32
+ /**
33
+ * Add a route to this node
34
+ */
35
+ addRoute(method: HTTPMethod, compiledRoute: CompiledRoute): void;
36
+ /**
37
+ * Get route for a specific HTTP method
38
+ */
39
+ getRoute(method: HTTPMethod): CompiledRoute | undefined;
40
+ /**
41
+ * Get all routes at this node
42
+ */
43
+ getAllRoutes(): CompiledRoute[];
44
+ }
45
+ /**
46
+ * Route matching result with extracted parameters
47
+ */
48
+ export interface RouteMatch {
49
+ route: Route;
50
+ params: Record<string, string>;
51
+ score: number;
52
+ }
53
+ /**
54
+ * High-performance route trie for O(log n) route matching
55
+ */
56
+ export declare class RouteTrie {
57
+ private root;
58
+ private compiledRoutes;
59
+ private methodTries;
60
+ constructor();
61
+ /**
62
+ * Compile a route pattern into segments
63
+ */
64
+ compileRoute(route: Route): CompiledRoute;
65
+ /**
66
+ * Parse path into segments
67
+ */
68
+ private parsePathSegments;
69
+ /**
70
+ * Calculate route priority (higher = more specific)
71
+ */
72
+ private calculateRoutePriority;
73
+ /**
74
+ * Add a route to the trie
75
+ */
76
+ addRoute(route: Route): void;
77
+ /**
78
+ * Insert compiled route into trie
79
+ */
80
+ private insertRoute;
81
+ /**
82
+ * Match a path against the trie
83
+ */
84
+ match(path: string, method: HTTPMethod): RouteMatch | null;
85
+ /**
86
+ * Recursively match path segments
87
+ */
88
+ private matchSegments;
89
+ /**
90
+ * Get all routes for debugging
91
+ */
92
+ getAllRoutes(): CompiledRoute[];
93
+ /**
94
+ * Remove a route from the trie
95
+ */
96
+ removeRoute(route: Route): void;
97
+ /**
98
+ * Clear the trie
99
+ */
100
+ clear(): void;
101
+ /**
102
+ * Get trie statistics for debugging
103
+ */
104
+ getStats(): {
105
+ totalRoutes: number;
106
+ totalNodes: number;
107
+ averageDepth: number;
108
+ methodDistribution: Record<string, number>;
109
+ };
110
+ /**
111
+ * Count total nodes in trie
112
+ */
113
+ private countNodes;
114
+ }