@stacksjs/bun-router 0.0.2 → 0.0.3

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 (128) hide show
  1. package/dist/{chunk-r15a48wc.js → chunk-cjdekj87.js} +536 -98
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +2 -2
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.js +454 -119
  6. package/package.json +6 -8
  7. package/dist/auth.d.ts +0 -77
  8. package/dist/cache/lru-cache.d.ts +0 -88
  9. package/dist/cache/middleware-memoization.d.ts +0 -101
  10. package/dist/cache/route-cache-warmer.d.ts +0 -125
  11. package/dist/cache/sqlite-cache.d.ts +0 -114
  12. package/dist/cache/streaming-cache.d.ts +0 -86
  13. package/dist/cli/colors.d.ts +0 -12
  14. package/dist/cli/index.d.ts +0 -10
  15. package/dist/cli/middleware.d.ts +0 -31
  16. package/dist/cli/openapi.d.ts +0 -17
  17. package/dist/cli/router.d.ts +0 -15
  18. package/dist/cli/routes.d.ts +0 -30
  19. package/dist/cli/utils.d.ts +0 -68
  20. package/dist/config.d.ts +0 -274
  21. package/dist/container/container.d.ts +0 -141
  22. package/dist/container/contextual-binding.d.ts +0 -112
  23. package/dist/container/decorators.d.ts +0 -114
  24. package/dist/container/service-provider.d.ts +0 -221
  25. package/dist/development/hot-reload.d.ts +0 -129
  26. package/dist/development/index.d.ts +0 -144
  27. package/dist/development/performance-profiler.d.ts +0 -152
  28. package/dist/development/route-debugger.d.ts +0 -102
  29. package/dist/development/route-inspector.d.ts +0 -142
  30. package/dist/development/typescript-utilities.d.ts +0 -116
  31. package/dist/docs.d.ts +0 -10
  32. package/dist/errors/circuit-breaker.d.ts +0 -138
  33. package/dist/errors/error-handler.d.ts +0 -57
  34. package/dist/errors/error-reporting.d.ts +0 -135
  35. package/dist/errors/exceptions.d.ts +0 -178
  36. package/dist/errors/graceful-degradation.d.ts +0 -130
  37. package/dist/errors/index.d.ts +0 -6
  38. package/dist/errors/router-errors.d.ts +0 -97
  39. package/dist/file-serving/static-files.d.ts +0 -98
  40. package/dist/middleware/auth.d.ts +0 -34
  41. package/dist/middleware/content_security_policy.d.ts +0 -54
  42. package/dist/middleware/cors.d.ts +0 -5
  43. package/dist/middleware/csrf.d.ts +0 -7
  44. package/dist/middleware/ddos_protection.d.ts +0 -47
  45. package/dist/middleware/file_security.d.ts +0 -23
  46. package/dist/middleware/file_upload.d.ts +0 -41
  47. package/dist/middleware/helmet.d.ts +0 -54
  48. package/dist/middleware/index.d.ts +0 -55
  49. package/dist/middleware/input_validation.d.ts +0 -46
  50. package/dist/middleware/json_body.d.ts +0 -4
  51. package/dist/middleware/performance_alerting.d.ts +0 -88
  52. package/dist/middleware/performance_dashboard.d.ts +0 -97
  53. package/dist/middleware/performance_monitor.d.ts +0 -236
  54. package/dist/middleware/pipeline.d.ts +0 -90
  55. package/dist/middleware/rate_limit.d.ts +0 -33
  56. package/dist/middleware/request_id.d.ts +0 -4
  57. package/dist/middleware/request_signing.d.ts +0 -96
  58. package/dist/middleware/request_tracer.d.ts +0 -76
  59. package/dist/middleware/response_cache.d.ts +0 -90
  60. package/dist/middleware/security.d.ts +0 -70
  61. package/dist/middleware/security_suite.d.ts +0 -46
  62. package/dist/middleware/session.d.ts +0 -7
  63. package/dist/model-binding/index.d.ts +0 -17
  64. package/dist/model-binding/model-middleware.d.ts +0 -80
  65. package/dist/model-binding/model-registry.d.ts +0 -125
  66. package/dist/model-binding.d.ts +0 -123
  67. package/dist/model-resolver-factory.d.ts +0 -31
  68. package/dist/observability/correlation.d.ts +0 -131
  69. package/dist/observability/health-checks.d.ts +0 -129
  70. package/dist/observability/index.d.ts +0 -92
  71. package/dist/observability/integration.d.ts +0 -112
  72. package/dist/observability/metrics.d.ts +0 -135
  73. package/dist/observability/tracing.d.ts +0 -112
  74. package/dist/optimization/bun-utilities.d.ts +0 -106
  75. package/dist/query-builder-integration.d.ts +0 -24
  76. package/dist/request/enhanced-request.d.ts +0 -143
  77. package/dist/request/macros.d.ts +0 -267
  78. package/dist/response/macros.d.ts +0 -207
  79. package/dist/response/response-factory.d.ts +0 -93
  80. package/dist/router/file-based-routing.d.ts +0 -40
  81. package/dist/router/file-streaming.d.ts +0 -6
  82. package/dist/router/fluent-router.d.ts +0 -179
  83. package/dist/router/fluent-routing.d.ts +0 -198
  84. package/dist/router/group-organization.d.ts +0 -5
  85. package/dist/router/handler-resolver.d.ts +0 -13
  86. package/dist/router/http-methods.d.ts +0 -10
  87. package/dist/router/index.d.ts +0 -114
  88. package/dist/router/middleware-integration.d.ts +0 -86
  89. package/dist/router/middleware.d.ts +0 -5
  90. package/dist/router/model-binding.d.ts +0 -7
  91. package/dist/router/optimized-route-matching.d.ts +0 -6
  92. package/dist/router/route-building.d.ts +0 -5
  93. package/dist/router/route-compiler.d.ts +0 -67
  94. package/dist/router/route-matching.d.ts +0 -5
  95. package/dist/router/route-trie.d.ts +0 -69
  96. package/dist/router/router.d.ts +0 -133
  97. package/dist/router/server.d.ts +0 -5
  98. package/dist/router/validation-integration.d.ts +0 -116
  99. package/dist/router/view-rendering.d.ts +0 -5
  100. package/dist/router/websocket.d.ts +0 -5
  101. package/dist/routing/route-caching.d.ts +0 -105
  102. package/dist/routing/route-throttling.d.ts +0 -112
  103. package/dist/routing/subdomain-routing.d.ts +0 -159
  104. package/dist/streaming/index.d.ts +0 -15
  105. package/dist/streaming/sse-handler.d.ts +0 -81
  106. package/dist/streaming/stream-handler.d.ts +0 -81
  107. package/dist/testing/auth-testing.d.ts +0 -107
  108. package/dist/testing/file-upload-testing.d.ts +0 -139
  109. package/dist/testing/index.d.ts +0 -10
  110. package/dist/testing/middleware-testing.d.ts +0 -99
  111. package/dist/testing/model-binding-testing.d.ts +0 -132
  112. package/dist/testing/performance-testing.d.ts +0 -202
  113. package/dist/testing/test-client.d.ts +0 -58
  114. package/dist/testing/test-request.d.ts +0 -43
  115. package/dist/testing/test-response.d.ts +0 -45
  116. package/dist/testing/types.d.ts +0 -206
  117. package/dist/testing/websocket-testing.d.ts +0 -170
  118. package/dist/types/controller-types.d.ts +0 -303
  119. package/dist/types/core.d.ts +0 -526
  120. package/dist/types/middleware-types.d.ts +0 -315
  121. package/dist/types/request-response-augmentation.d.ts +0 -373
  122. package/dist/types/route-inference.d.ts +0 -287
  123. package/dist/types.d.ts +0 -1620
  124. package/dist/utils/index.d.ts +0 -1
  125. package/dist/utils/query-preservation.d.ts +0 -31
  126. package/dist/utils.d.ts +0 -69
  127. package/dist/validation/validator.d.ts +0 -169
  128. package/dist/websocket/clustering.d.ts +0 -114
@@ -1,5 +0,0 @@
1
- import type { Router } from './router';
2
- /**
3
- * Route building extension for Router class
4
- */
5
- export declare function registerRouteBuilding(RouterClass: typeof Router): void;
@@ -1,67 +0,0 @@
1
- import { RouteTrie } from './route-trie';
2
- import type { CompiledRoute } from './route-trie';
3
- import type { HTTPMethod, MatchResult, PatternMatchResult, Route } from '../types';
4
- /**
5
- * Route compilation options
6
- */
7
- export declare interface RouteCompilerOptions {
8
- enableCaching: boolean
9
- enableMethodGrouping: boolean
10
- enablePriorityOptimization: boolean
11
- cacheSize: number
12
- precompilePatterns: boolean
13
- }
14
- /**
15
- * Route matching statistics for performance monitoring
16
- */
17
- export declare interface RouteMatchStats {
18
- totalMatches: number
19
- cacheHits: number
20
- cacheMisses: number
21
- averageMatchTime: number
22
- trieDepth: number
23
- methodDistribution: Record<string, number>
24
- }
25
- /**
26
- * High-performance route compiler with pre-compilation and optimization
27
- */
28
- export declare class RouteCompiler {
29
- private trie: RouteTrie;
30
- private matchCache: Map<string, MatchResult | null>;
31
- private cacheKeys: string[];
32
- private stats: RouteMatchStats;
33
- private options: RouteCompilerOptions;
34
- constructor(options?: Partial<RouteCompilerOptions>);
35
- addRoute(route: Route): boolean;
36
- private checkForDuplicateRoute(route: Route): boolean;
37
- private patternCache: Map<string, { exec: (url: URL) => PatternMatchResult | null }>;
38
- private extractParamNames(path: string): string[];
39
- private precompileRoutePattern(route: Route): void;
40
- private convertToURLPattern(path: string, constraints?: Record<string, string>): { exec: (pathname: string) => { groups?: Record<string, string> } | null };
41
- match(path: string, method: HTTPMethod): MatchResult | null;
42
- private addToCache(key: string, value: MatchResult | null): void;
43
- private updateCacheLRU(key: string): void;
44
- private updateMatchTime(startTime: number): void;
45
- getCompiledRoutes(): CompiledRoute[];
46
- getRoutesByMethod(): Map<HTTPMethod, CompiledRoute[]>;
47
- warmCache(commonPaths: Array<{ path: string, method: HTTPMethod }>, options?: { force?: boolean, precompile?: boolean }): { warmedPaths: number, cacheSize: number, hitRate: number };
48
- clear(): void;
49
- getStats(): RouteMatchStats;
50
- getCacheStats(): {
51
- size: number
52
- maxSize: number
53
- hitRate: number
54
- enabled: boolean
55
- };
56
- optimizeRouteOrder(_usageStats: Record<string, number>): void;
57
- getRouteConflicts(): Array<{
58
- routes: CompiledRoute[]
59
- conflictType: 'overlap' | 'duplicate' | 'ambiguous'
60
- severity: 'low' | 'medium' | 'high'
61
- }>;
62
- private routesConflict(route1: CompiledRoute, route2: CompiledRoute): boolean;
63
- private patternsOverlap(segments1: any[], segments2: any[]): boolean;
64
- private getConflictSeverity(route1: CompiledRoute, route2: CompiledRoute): 'low' | 'medium' | 'high';
65
- private getConflictType(route1: CompiledRoute, route2: CompiledRoute): 'overlap' | 'duplicate' | 'ambiguous';
66
- private hasAmbiguousParameters(route1: CompiledRoute, route2: CompiledRoute): boolean;
67
- }
@@ -1,5 +0,0 @@
1
- import type { Router } from './router';
2
- /**
3
- * Route matching extension for Router class
4
- */
5
- export declare function registerRouteMatching(RouterClass: typeof Router): void;
@@ -1,69 +0,0 @@
1
- import type { HTTPMethod, Route } from '../types';
2
- export declare interface RouteSegment {
3
- type: RouteSegmentType
4
- value: string
5
- paramName?: string
6
- pattern?: RegExp
7
- optional?: boolean
8
- }
9
- export declare interface CompiledRoute {
10
- route: Route
11
- segments: RouteSegment[]
12
- paramNames: string[]
13
- priority: number
14
- staticScore: number
15
- dynamicScore: number
16
- }
17
- /**
18
- * Route matching result with extracted parameters
19
- */
20
- export declare interface RouteMatch {
21
- route: Route
22
- params: Record<string, string>
23
- score: number
24
- }
25
- /**
26
- * Route segment types for the trie
27
- */
28
- export type RouteSegmentType = 'static' | 'parameter' | 'wildcard' | 'optional'
29
- /**
30
- * Trie node for efficient route matching
31
- */
32
- export declare class TrieNode {
33
- children: Map<string, TrieNode>;
34
- paramChild: TrieNode | null;
35
- wildcardChild: TrieNode | null;
36
- routes: Map<HTTPMethod, CompiledRoute>;
37
- paramName: string | null;
38
- pattern: RegExp | null;
39
- isEndpoint: boolean;
40
- addRoute(method: HTTPMethod, compiledRoute: CompiledRoute): void;
41
- getRoute(method: HTTPMethod): CompiledRoute | undefined;
42
- getAllRoutes(): CompiledRoute[];
43
- }
44
- /**
45
- * High-performance route trie for O(log n) route matching
46
- */
47
- export declare class RouteTrie {
48
- private root: TrieNode;
49
- private compiledRoutes: Map<string, CompiledRoute>;
50
- private methodTries: Map<HTTPMethod, TrieNode>;
51
- constructor();
52
- compileRoute(route: Route): CompiledRoute;
53
- private parsePathSegments(path: string): RouteSegment[];
54
- private calculateRoutePriority(segments: RouteSegment[]): number;
55
- addRoute(route: Route): void;
56
- private insertRoute(node: TrieNode, compiled: CompiledRoute, segmentIndex: number): void;
57
- match(path: string, method: HTTPMethod): RouteMatch | null;
58
- private matchSegments(node: TrieNode, segments: string[], segmentIndex: number, params: Record<string, string>, method: HTTPMethod): RouteMatch | null;
59
- getAllRoutes(): CompiledRoute[];
60
- removeRoute(route: Route): void;
61
- clear(): void;
62
- getStats(): {
63
- totalRoutes: number
64
- totalNodes: number
65
- averageDepth: number
66
- methodDistribution: Record<string, number>
67
- };
68
- private countNodes(node: TrieNode): number;
69
- }
@@ -1,133 +0,0 @@
1
- import type { Server } from 'bun';
2
- import type { ActionHandler, CookieOptions, EnhancedRequest, MiddlewareHandler, Route, RouteGroup, RouteHandler, RouterConfig, WebSocketConfig, WebSocketData, } from '../types';
3
- import type { MiddlewareDependency, MiddlewarePipeline, MiddlewarePipelineStats, MiddlewareSkipCondition } from '../middleware/pipeline';
4
- export type {
5
- ActionHandler,
6
- MiddlewareHandler,
7
- Route,
8
- RouteGroup,
9
- RouteHandler,
10
- RouterConfig,
11
- WebSocketConfig,
12
- };
13
- /**
14
- * Route compiler interface for pattern matching
15
- */
16
- export declare interface RouteCompiler {
17
- compile: (path: string) => RegExp
18
- match: (path: string, pattern: RegExp) => Record<string, string> | null
19
- }
20
- /**
21
- * Middleware cache info interface
22
- */
23
- export declare interface MiddlewareCacheInfo {
24
- size: number
25
- routes: string[]
26
- hitRate: number
27
- }
28
- // Middleware condition type
29
- export type MiddlewareCondition = (req: EnhancedRequest) => boolean
30
- /**
31
- * Unified Router class with advanced middleware patterns
32
- */
33
- export declare class Router {
34
- routes: Route[];
35
- currentGroup: RouteGroup | null;
36
- globalMiddleware: MiddlewareHandler[];
37
- namedRoutes: Map<string, Route>;
38
- fallbackHandler: ActionHandler | null;
39
- patterns: Map<string, string>;
40
- currentDomain: string | null;
41
- domains: Record<string, Route[]>;
42
- serverInstance: Server<WebSocketData> | null;
43
- wsConfig: WebSocketConfig | null;
44
- errorHandler: ((error: Error) => Response | Promise<Response>) | null;
45
- templateCache: Map<string, string>;
46
- routeCache: Map<string, { route: Route, params: Record<string, string> }>;
47
- staticRoutes: Map<string, Map<string, Route>>;
48
- precompiledPatterns: Map<string, RegExp>;
49
- domainPatternCache: Map<string, RegExp>;
50
- routeCompiler: RouteCompiler | null;
51
- private middlewareGroups: Map<string, MiddlewareHandler[]>;
52
- private namedMiddleware: Map<string, (params?: string) => MiddlewareHandler>;
53
- private conditionalMiddleware: Array<{ condition: MiddlewareCondition, middleware: MiddlewareHandler[] }>;
54
- _middlewarePipeline?: MiddlewarePipeline;
55
- config: RouterConfig;
56
- constructor(config?: Partial<RouterConfig>);
57
- private initializeDefaultMiddleware(): void;
58
- middlewareGroup(name: string, middlewareNames: string[]): this;
59
- middlewareGroupRoutes(name: string): RouteGroupBuilder;
60
- when(condition: MiddlewareCondition): ConditionalBuilder;
61
- middleware(middlewareName: string): MiddlewareBuilder;
62
- getServer(): Server<WebSocketData> | null;
63
- extend(methods: Record<string, (...args: unknown[]) => unknown>): Router;
64
- invalidateCache(): void;
65
- registerRoute(method: string, path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
66
- resolveMiddleware(middleware: string | MiddlewareHandler): Promise<MiddlewareHandler | null>;
67
- get(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
68
- post(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
69
- put(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
70
- patch(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
71
- delete(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
72
- options(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
73
- match(methods: string[], path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
74
- any(path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: (string | MiddlewareHandler)[]): Promise<Router>;
75
- fallback(handler: ActionHandler): Router;
76
- route(name: string, params?: Record<string, string>): string;
77
- onError(handler: (error: Error) => Response | Promise<Response>): Router;
78
- redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
79
- permanentRedirect(url: string): Response;
80
- redirectRoute(from: string, to: string, status?: 301 | 302 | 303 | 307 | 308): Promise<Router>;
81
- serve(options?: { port?: number, hostname?: string }): Promise<Server<WebSocketData>>;
82
- handleRequest(req: Request): Promise<Response>;
83
- getAllowedMethods(path: string, domain?: string): string[];
84
- matchRoute(path: string, method: string, domain?: string): { route: Route, params: Record<string, string> } | undefined;
85
- enhanceRequest(req: Request, params?: Record<string, string>): EnhancedRequest;
86
- applyModifiedCookies(response: Response, req: EnhancedRequest): Response;
87
- serializeCookie(name: string, value: string, options?: CookieOptions): string;
88
- buildMiddlewareChain(middlewares: MiddlewareHandler[]): (req: EnhancedRequest) => Promise<Response | null>;
89
- runMiddleware(req: EnhancedRequest, middlewareStack: MiddlewareHandler[]): Promise<Response | null>;
90
- resolveHandler(handler: ActionHandler, req: EnhancedRequest): Promise<Response>;
91
- use(middleware: (string | MiddlewareHandler)[]): Promise<Router>;
92
- group(options: { prefix?: string, middleware?: (string | MiddlewareHandler)[] }, callback: () => void | Promise<void>): Router;
93
- addRoute(route: Route): this;
94
- registerMiddlewareDependency(dependency: MiddlewareDependency): this;
95
- registerMiddlewareSkipConditions(_middlewareName: string, _conditions: MiddlewareSkipCondition[]): this;
96
- getMiddlewareStats(): MiddlewarePipelineStats | Record<string, never>;
97
- getMiddlewareCacheInfo(): MiddlewareCacheInfo;
98
- clearMiddlewareCache(): this;
99
- executeMiddleware(middleware: MiddlewareHandler[], request: EnhancedRequest, handler: () => Promise<Response>): Promise<Response>;
100
- }
101
- /**
102
- * Builder for conditional middleware
103
- */
104
- export declare class ConditionalBuilder {
105
- private router: Router;
106
- private condition: MiddlewareCondition;
107
- constructor(router: Router, condition: MiddlewareCondition);
108
- middleware(middlewareName: string): this;
109
- }
110
- /**
111
- * Builder for middleware with parameters
112
- */
113
- export declare class MiddlewareBuilder {
114
- private router: Router;
115
- private middleware: MiddlewareHandler[];
116
- constructor(router: Router, middleware: MiddlewareHandler[]);
117
- get(_path: string, _handler: RouteHandler): this;
118
- post(_path: string, _handler: RouteHandler): this;
119
- put(_path: string, _handler: RouteHandler): this;
120
- delete(_path: string, _handler: RouteHandler): this;
121
- }
122
- /**
123
- * Builder for route groups with middleware
124
- */
125
- export declare class RouteGroupBuilder {
126
- private router: Router;
127
- private middleware: MiddlewareHandler[];
128
- constructor(router: Router, middleware: MiddlewareHandler[]);
129
- get(_path: string, _handler: RouteHandler): this;
130
- post(_path: string, _handler: RouteHandler): this;
131
- put(_path: string, _handler: RouteHandler): this;
132
- delete(_path: string, _handler: RouteHandler): this;
133
- }
@@ -1,5 +0,0 @@
1
- import type { Router } from './router';
2
- /**
3
- * Server handling extension for Router class
4
- */
5
- export declare function registerServerHandling(RouterClass: typeof Router): void;
@@ -1,116 +0,0 @@
1
- import type { EnhancedRequest, MiddlewareHandler, RouteHandler } from '../types';
2
- import type { ValidationRules, ValidatorConfig } from '../validation/validator';
3
- /**
4
- * Router middleware factory for request/response enhancements
5
- */
6
- export declare function createEnhancementMiddleware(): void;
7
- /**
8
- * Factory function to create validation middleware builder
9
- */
10
- export declare function validate(): ValidationMiddlewareBuilder;
11
- /**
12
- * Fluent router factory
13
- */
14
- export declare function createFluentRouter(): FluentRouter;
15
- /**
16
- * Route helper functions
17
- */
18
- export declare const RouteHelpers: {
19
- validated: (method: string, path: string, handler: RouteHandler, rules: ValidationRules, config?: ValidatorConfig) => RouteBuilder
20
- apiRoute: (method: string, path: string, handler: RouteHandler, rules?: ValidationRules) => RouteBuilder
21
- resourceRoute: (basePath: string, handlers: ResourceHandlers, validation?: ResourceValidation) => RouteBuilder[]
22
- };
23
- /**
24
- * Middleware composition helpers
25
- */
26
- export declare const MiddlewareHelpers: {
27
- /**
28
- * Compose multiple middleware into one
29
- */
30
- compose: (...middleware: MiddlewareHandler[]) => any;
31
- /**
32
- * Create conditional middleware
33
- */
34
- when: ( condition: (req: EnhancedRequest) => boolean, middleware: MiddlewareHandler, ) => any;
35
- /**
36
- * Create middleware that runs unless condition is met
37
- */
38
- unless: ( condition: (req: EnhancedRequest) => boolean, middleware: MiddlewareHandler, ) => any;
39
- /**
40
- * Create middleware group
41
- */
42
- group: (middleware: MiddlewareHandler[]) => any
43
- };
44
- /**
45
- * Request/Response enhancement presets
46
- */
47
- export declare const EnhancementPresets: {
48
- api: () => EnhancementMiddleware[]
49
- web: () => EnhancementMiddleware[]
50
- validation: (rules: ValidationRules, config?: ValidatorConfig) => EnhancementMiddleware[]
51
- };
52
- /** Resource handlers configuration */
53
- export declare interface ResourceHandlers {
54
- index?: RouteHandler
55
- show?: RouteHandler
56
- store?: RouteHandler
57
- update?: RouteHandler
58
- destroy?: RouteHandler
59
- }
60
- /** Resource validation configuration */
61
- export declare interface ResourceValidation {
62
- store?: ValidationRules
63
- update?: ValidationRules
64
- }
65
- /** Enhancement middleware type */
66
- export type EnhancementMiddleware = (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>
67
- /**
68
- * Route builder with validation support
69
- */
70
- export declare class RouteBuilder {
71
- private validationRules?: ValidationRules;
72
- private validatorConfig?: ValidatorConfig;
73
- private method: string;
74
- private path: string;
75
- private handler: RouteHandler;
76
- constructor(method: string, path: string, handler: RouteHandler);
77
- validate(rules: ValidationRules, config?: ValidatorConfig): this;
78
- build(): { method: string, path: string, handler: RouteHandler, middleware?: MiddlewareHandler[] };
79
- }
80
- /**
81
- * Fluent router for enhanced routing functionality
82
- */
83
- export declare class FluentRouter {
84
- private routes: Array<{
85
- method: string
86
- path: string
87
- handler: RouteHandler
88
- middleware?: MiddlewareHandler[]
89
- }>;
90
- get(path: string, handler: RouteHandler): RouteBuilder;
91
- post(path: string, handler: RouteHandler): RouteBuilder;
92
- put(path: string, handler: RouteHandler): RouteBuilder;
93
- patch(path: string, handler: RouteHandler): RouteBuilder;
94
- delete(path: string, handler: RouteHandler): RouteBuilder;
95
- register(routeBuilder: RouteBuilder): void;
96
- getRoutes(): Array<{
97
- method: string
98
- path: string
99
- handler: RouteHandler
100
- middleware?: MiddlewareHandler[]
101
- }>;
102
- }
103
- /**
104
- * Validation middleware factory with fluent API
105
- */
106
- export declare class ValidationMiddlewareBuilder {
107
- private rules: ValidationRules;
108
- private config: ValidatorConfig;
109
- field(name: string, rules: string): this;
110
- fields(rules: ValidationRules): this;
111
- configure(config: ValidatorConfig): this;
112
- stopOnFirstFailure(): this;
113
- messages(messages: Record<string, string>): this;
114
- attributes(attributes: Record<string, string>): this;
115
- build(): MiddlewareHandler;
116
- }
@@ -1,5 +0,0 @@
1
- import type { Router } from './router';
2
- /**
3
- * View rendering extension for Router class
4
- */
5
- export declare function registerViewRendering(RouterClass: typeof Router): void;
@@ -1,5 +0,0 @@
1
- import type { Router } from './router';
2
- /**
3
- * WebSocket extension for Router class
4
- */
5
- export declare function registerWebSocketHandling(RouterClass: typeof Router): void;
@@ -1,105 +0,0 @@
1
- import { LRUCache } from '../cache/lru-cache';
2
- import type { EnhancedRequest } from '../types';
3
- /**
4
- * Create route caching middleware
5
- */
6
- export declare function createRouteCacheMiddleware(config: RouteCacheConfig): void;
7
- /**
8
- * Global route cache manager instance
9
- */
10
- export declare const routeCacheManager: RouteCacheManager;
11
- /**
12
- * Factory functions for common cache configurations
13
- */
14
- export declare const RouteCacheFactory: {
15
- /**
16
- * Short-term cache (5 minutes)
17
- */
18
- short: (tags: string[] = []) => any;
19
- /**
20
- * Medium-term cache (1 hour)
21
- */
22
- medium: (tags: string[] = []) => any;
23
- /**
24
- * Long-term cache (24 hours)
25
- */
26
- long: (tags: string[] = []) => any;
27
- /**
28
- * API response cache with common settings
29
- */
30
- api: (tags: string[] = []) => any;
31
- /**
32
- * Static content cache
33
- */
34
- static: (tags: string[] = []) => any;
35
- /**
36
- * User-specific cache
37
- */
38
- user: (tags: string[] = []) => any
39
- };
40
- /**
41
- * Cache invalidation utilities
42
- */
43
- export declare const CacheInvalidation: {
44
- /**
45
- * Invalidate by tags
46
- */
47
- byTags: (tags: string[]) => any;
48
- /**
49
- * Invalidate all user-related cache
50
- */
51
- forUser: (userId: string) => any;
52
- /**
53
- * Invalidate model-related cache
54
- */
55
- forModel: (modelName: string, id?: string) => any;
56
- /**
57
- * Clear all cache
58
- */
59
- all: () => any
60
- };
61
- /**
62
- * Route caching configuration
63
- */
64
- export declare interface RouteCacheConfig {
65
- ttl?: number
66
- maxSize?: number
67
- tags?: string[]
68
- varyBy?: string[]
69
- excludeQuery?: string[]
70
- condition?: (req: EnhancedRequest) => boolean
71
- }
72
- /**
73
- * Cached response metadata
74
- */
75
- export declare interface CachedResponse {
76
- response: Response
77
- headers: Record<string, string>
78
- status: number
79
- body: string | Uint8Array
80
- timestamp: number
81
- ttl?: number
82
- tags: string[]
83
- etag?: string
84
- }
85
- /**
86
- * Cache key generator for route responses
87
- */
88
- export declare class RouteCacheKeyGenerator {
89
- static generateKey(req: EnhancedRequest, config: RouteCacheConfig): string;
90
- }
91
- /**
92
- * Route cache manager with tag-based invalidation
93
- */
94
- export declare class RouteCacheManager {
95
- private cache: LRUCache<CachedResponse>;
96
- private tagIndex: Map<string, Set<string>>;
97
- private keyTags: Map<string, Set<string>>;
98
- constructor(maxSize?: number);
99
- get(key: string): Promise<CachedResponse | null>;
100
- set(key: string, response: CachedResponse): Promise<void>;
101
- delete(key: string): boolean;
102
- invalidateByTags(tags: string[]): number;
103
- clear(): void;
104
- getStats(): ReturnType<LRUCache<CachedResponse>['getStats']> & { totalTags: number, totalKeyTagMappings: number };
105
- }
@@ -1,112 +0,0 @@
1
- import { LRUCache } from '../cache/lru-cache';
2
- import type { EnhancedRequest, MiddlewareHandler, ThrottlePattern } from '../types';
3
- /**
4
- * Create rate limiting middleware
5
- */
6
- export declare function createRateLimitMiddleware(config: ThrottleConfig, name?: string): MiddlewareHandler;
7
- /**
8
- * Parse throttle string (Laravel-style) with enhanced time unit support
9
- * Examples: '60,1' -> 60 requests per 1 minute
10
- * '100,30s' -> 100 requests per 30 seconds
11
- * '1000,1h' -> 1000 requests per 1 hour
12
- * '60' -> 60 requests per 1 minute (default)
13
- */
14
- export declare function parseThrottleString(throttleStr: ThrottlePattern): ThrottleConfig;
15
- /**
16
- * Global rate limit registry instance
17
- */
18
- export declare const rateLimitRegistry: RateLimitRegistry;
19
- /**
20
- * Factory functions for common rate limiting scenarios
21
- */
22
- export declare const ThrottleFactory: {
23
- /**
24
- * API rate limiting (60 requests per minute)
25
- */
26
- api: (maxAttempts: number?, windowMinutes: number?) => any;
27
- /**
28
- * Authentication rate limiting (5 attempts per 15 minutes)
29
- */
30
- auth: () => any;
31
- /**
32
- * Upload rate limiting (10 uploads per hour)
33
- */
34
- upload: () => any;
35
- /**
36
- * Search rate limiting (100 searches per 10 minutes)
37
- */
38
- search: () => any;
39
- /**
40
- * Per-user rate limiting
41
- */
42
- perUser: (maxAttempts: number, windowMinutes: number) => any;
43
- /**
44
- * Per-IP rate limiting
45
- */
46
- perIP: (maxAttempts: number, windowMinutes: number) => any;
47
- /**
48
- * Global rate limiting (shared across all users)
49
- */
50
- global: (maxAttempts: number, windowMinutes: number) => any
51
- };
52
- /**
53
- * Rate limit utilities
54
- */
55
- export declare const RateLimitUtils: {
56
- /**
57
- * Create throttle middleware from string (Laravel-style)
58
- */
59
- fromString: (throttleStr: string, name?: string) => any;
60
- /**
61
- * Get rate limit info for a request without incrementing
62
- */
63
- getInfo: (req: EnhancedRequest, config: ThrottleConfig) => Promise<RateLimitInfo>;
64
- /**
65
- * Reset rate limit for a specific key
66
- */
67
- reset: (limiterName: string, key: string) => any
68
- };
69
- /**
70
- * Throttle configuration for rate limiting
71
- */
72
- export declare interface ThrottleConfig {
73
- maxAttempts: number
74
- windowMs: number
75
- keyGenerator?: (req: EnhancedRequest) => string
76
- skipIf?: (req: EnhancedRequest) => boolean
77
- onLimitReached?: (req: EnhancedRequest, info: RateLimitInfo) => Response
78
- headers?: boolean
79
- maxRequests?: number
80
- }
81
- /**
82
- * Rate limit information
83
- */
84
- export declare interface RateLimitInfo {
85
- totalHits: number
86
- totalHits24h?: number
87
- resetTime: Date
88
- remaining: number
89
- limit: number
90
- windowMs: number
91
- }
92
- /**
93
- * Rate limiter implementation
94
- */
95
- export declare class RateLimiter {
96
- private cache: LRUCache<RateLimitEntry>;
97
- private config: ThrottleConfig;
98
- constructor(config: ThrottleConfig, cacheSize?: number);
99
- checkLimit(req: EnhancedRequest): Promise<{ allowed: boolean, info: RateLimitInfo }>;
100
- private generateKey(req: EnhancedRequest): string;
101
- private getClientIP(req: EnhancedRequest): string;
102
- getStats(): ReturnType<LRUCache<RateLimitEntry>['getStats']> & { config: { maxAttempts: number, windowMs: number } };
103
- }
104
- /**
105
- * Global rate limiters registry
106
- */
107
- export declare class RateLimitRegistry {
108
- private limiters: any;
109
- register(name: string, config: ThrottleConfig): RateLimiter;
110
- get(name: string): RateLimiter | undefined;
111
- getOrCreate(name: string, config: ThrottleConfig): RateLimiter;
112
- }