@stacksjs/bun-router 0.0.2

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 (131) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +397 -0
  3. package/bin/cli.ts +9 -0
  4. package/dist/auth.d.ts +77 -0
  5. package/dist/cache/lru-cache.d.ts +88 -0
  6. package/dist/cache/middleware-memoization.d.ts +101 -0
  7. package/dist/cache/route-cache-warmer.d.ts +125 -0
  8. package/dist/cache/sqlite-cache.d.ts +114 -0
  9. package/dist/cache/streaming-cache.d.ts +86 -0
  10. package/dist/chunk-r15a48wc.js +25448 -0
  11. package/dist/cli/colors.d.ts +12 -0
  12. package/dist/cli/index.d.ts +10 -0
  13. package/dist/cli/middleware.d.ts +31 -0
  14. package/dist/cli/openapi.d.ts +17 -0
  15. package/dist/cli/router.d.ts +15 -0
  16. package/dist/cli/routes.d.ts +30 -0
  17. package/dist/cli/utils.d.ts +68 -0
  18. package/dist/cli.d.ts +0 -0
  19. package/dist/cli.js +3195 -0
  20. package/dist/config.d.ts +274 -0
  21. package/dist/container/container.d.ts +141 -0
  22. package/dist/container/contextual-binding.d.ts +112 -0
  23. package/dist/container/decorators.d.ts +114 -0
  24. package/dist/container/service-provider.d.ts +221 -0
  25. package/dist/development/hot-reload.d.ts +129 -0
  26. package/dist/development/index.d.ts +144 -0
  27. package/dist/development/performance-profiler.d.ts +152 -0
  28. package/dist/development/route-debugger.d.ts +102 -0
  29. package/dist/development/route-inspector.d.ts +142 -0
  30. package/dist/development/typescript-utilities.d.ts +116 -0
  31. package/dist/docs.d.ts +10 -0
  32. package/dist/errors/circuit-breaker.d.ts +138 -0
  33. package/dist/errors/error-handler.d.ts +57 -0
  34. package/dist/errors/error-reporting.d.ts +135 -0
  35. package/dist/errors/exceptions.d.ts +178 -0
  36. package/dist/errors/graceful-degradation.d.ts +130 -0
  37. package/dist/errors/index.d.ts +6 -0
  38. package/dist/errors/router-errors.d.ts +97 -0
  39. package/dist/file-serving/static-files.d.ts +98 -0
  40. package/dist/index.d.ts +10 -0
  41. package/dist/index.js +13417 -0
  42. package/dist/middleware/auth.d.ts +34 -0
  43. package/dist/middleware/content_security_policy.d.ts +54 -0
  44. package/dist/middleware/cors.d.ts +5 -0
  45. package/dist/middleware/csrf.d.ts +7 -0
  46. package/dist/middleware/ddos_protection.d.ts +47 -0
  47. package/dist/middleware/file_security.d.ts +23 -0
  48. package/dist/middleware/file_upload.d.ts +41 -0
  49. package/dist/middleware/helmet.d.ts +54 -0
  50. package/dist/middleware/index.d.ts +55 -0
  51. package/dist/middleware/input_validation.d.ts +46 -0
  52. package/dist/middleware/json_body.d.ts +4 -0
  53. package/dist/middleware/performance_alerting.d.ts +88 -0
  54. package/dist/middleware/performance_dashboard.d.ts +97 -0
  55. package/dist/middleware/performance_monitor.d.ts +236 -0
  56. package/dist/middleware/pipeline.d.ts +90 -0
  57. package/dist/middleware/rate_limit.d.ts +33 -0
  58. package/dist/middleware/request_id.d.ts +4 -0
  59. package/dist/middleware/request_signing.d.ts +96 -0
  60. package/dist/middleware/request_tracer.d.ts +76 -0
  61. package/dist/middleware/response_cache.d.ts +90 -0
  62. package/dist/middleware/security.d.ts +70 -0
  63. package/dist/middleware/security_suite.d.ts +46 -0
  64. package/dist/middleware/session.d.ts +7 -0
  65. package/dist/model-binding/index.d.ts +17 -0
  66. package/dist/model-binding/model-middleware.d.ts +80 -0
  67. package/dist/model-binding/model-registry.d.ts +125 -0
  68. package/dist/model-binding.d.ts +123 -0
  69. package/dist/model-resolver-factory.d.ts +31 -0
  70. package/dist/observability/correlation.d.ts +131 -0
  71. package/dist/observability/health-checks.d.ts +129 -0
  72. package/dist/observability/index.d.ts +92 -0
  73. package/dist/observability/integration.d.ts +112 -0
  74. package/dist/observability/metrics.d.ts +135 -0
  75. package/dist/observability/tracing.d.ts +112 -0
  76. package/dist/optimization/bun-utilities.d.ts +106 -0
  77. package/dist/query-builder-integration.d.ts +24 -0
  78. package/dist/request/enhanced-request.d.ts +143 -0
  79. package/dist/request/macros.d.ts +267 -0
  80. package/dist/response/macros.d.ts +207 -0
  81. package/dist/response/response-factory.d.ts +93 -0
  82. package/dist/router/file-based-routing.d.ts +40 -0
  83. package/dist/router/file-streaming.d.ts +6 -0
  84. package/dist/router/fluent-router.d.ts +179 -0
  85. package/dist/router/fluent-routing.d.ts +198 -0
  86. package/dist/router/group-organization.d.ts +5 -0
  87. package/dist/router/handler-resolver.d.ts +13 -0
  88. package/dist/router/http-methods.d.ts +10 -0
  89. package/dist/router/index.d.ts +114 -0
  90. package/dist/router/middleware-integration.d.ts +86 -0
  91. package/dist/router/middleware.d.ts +5 -0
  92. package/dist/router/model-binding.d.ts +7 -0
  93. package/dist/router/optimized-route-matching.d.ts +6 -0
  94. package/dist/router/route-building.d.ts +5 -0
  95. package/dist/router/route-compiler.d.ts +67 -0
  96. package/dist/router/route-matching.d.ts +5 -0
  97. package/dist/router/route-trie.d.ts +69 -0
  98. package/dist/router/router.d.ts +133 -0
  99. package/dist/router/server.d.ts +5 -0
  100. package/dist/router/validation-integration.d.ts +116 -0
  101. package/dist/router/view-rendering.d.ts +5 -0
  102. package/dist/router/websocket.d.ts +5 -0
  103. package/dist/routing/route-caching.d.ts +105 -0
  104. package/dist/routing/route-throttling.d.ts +112 -0
  105. package/dist/routing/subdomain-routing.d.ts +159 -0
  106. package/dist/streaming/index.d.ts +15 -0
  107. package/dist/streaming/sse-handler.d.ts +81 -0
  108. package/dist/streaming/stream-handler.d.ts +81 -0
  109. package/dist/testing/auth-testing.d.ts +107 -0
  110. package/dist/testing/file-upload-testing.d.ts +139 -0
  111. package/dist/testing/index.d.ts +10 -0
  112. package/dist/testing/middleware-testing.d.ts +99 -0
  113. package/dist/testing/model-binding-testing.d.ts +132 -0
  114. package/dist/testing/performance-testing.d.ts +202 -0
  115. package/dist/testing/test-client.d.ts +58 -0
  116. package/dist/testing/test-request.d.ts +43 -0
  117. package/dist/testing/test-response.d.ts +45 -0
  118. package/dist/testing/types.d.ts +206 -0
  119. package/dist/testing/websocket-testing.d.ts +170 -0
  120. package/dist/types/controller-types.d.ts +303 -0
  121. package/dist/types/core.d.ts +526 -0
  122. package/dist/types/middleware-types.d.ts +315 -0
  123. package/dist/types/request-response-augmentation.d.ts +373 -0
  124. package/dist/types/route-inference.d.ts +287 -0
  125. package/dist/types.d.ts +1620 -0
  126. package/dist/utils/index.d.ts +1 -0
  127. package/dist/utils/query-preservation.d.ts +31 -0
  128. package/dist/utils.d.ts +69 -0
  129. package/dist/validation/validator.d.ts +169 -0
  130. package/dist/websocket/clustering.d.ts +114 -0
  131. package/package.json +81 -0
@@ -0,0 +1,135 @@
1
+ import type { ErrorContext, RouterException } from './exceptions';
2
+ /**
3
+ * Factory function to create error reporting manager
4
+ */
5
+ export declare function createErrorReporting(configs: ErrorReportingConfig[]): ErrorReportingManager;
6
+ /**
7
+ * Default configuration presets
8
+ */
9
+ export declare const ErrorReportingPresets: {
10
+ sentry: (dsn: string, environment?) => any;
11
+ bugsnag: (apiKey: string, environment?) => any;
12
+ development: () => any
13
+ };
14
+ export declare interface ErrorReportingConfig {
15
+ enabled: boolean
16
+ service: 'sentry' | 'bugsnag' | 'custom'
17
+ dsn?: string
18
+ apiKey?: string
19
+ environment?: string
20
+ release?: string
21
+ sampleRate?: number
22
+ beforeSend?: (error: Error, context: ErrorContext) => Error | null
23
+ filters?: {
24
+ ignoreErrors?: (string | RegExp)[]
25
+ ignoreCodes?: string[]
26
+ ignoreUrls?: (string | RegExp)[]
27
+ allowUrls?: (string | RegExp)[]
28
+ }
29
+ tags?: Record<string, string>
30
+ user?: {
31
+ id?: string
32
+ email?: string
33
+ username?: string
34
+ }
35
+ extra?: Record<string, any>
36
+ breadcrumbs?: {
37
+ enabled: boolean
38
+ maxBreadcrumbs: number
39
+ }
40
+ performance?: {
41
+ enabled: boolean
42
+ tracesSampleRate: number
43
+ }
44
+ }
45
+ export declare interface ErrorReport {
46
+ error: RouterException
47
+ context: ErrorContext
48
+ fingerprint?: string[]
49
+ tags?: Record<string, string>
50
+ extra?: Record<string, any>
51
+ user?: Record<string, any>
52
+ level?: 'debug' | 'info' | 'warning' | 'error' | 'fatal'
53
+ }
54
+ export declare interface ErrorReporter {
55
+ report: (error: RouterException, context?: ErrorContext) => Promise<string | null>
56
+ addBreadcrumb: (message: string, category?: string, level?: string, data?: Record<string, any>) => void
57
+ setUser: (user: Record<string, any>) => void
58
+ setTag: (key: string, value: string) => void
59
+ setExtra: (key: string, value: any) => void
60
+ setContext: (key: string, context: Record<string, any>) => void
61
+ close: (timeout?: number) => Promise<boolean>
62
+ }
63
+ /**
64
+ * Sentry error reporter implementation
65
+ */
66
+ export declare class SentryReporter implements ErrorReporter {
67
+ private config: ErrorReportingConfig;
68
+ private sentry: any;
69
+ constructor(config: ErrorReportingConfig);
70
+ private initializeSentry(): Promise<void>;
71
+ report(error: RouterException, context?: ErrorContext): Promise<string | null>;
72
+ addBreadcrumb(message: string, category?: any, level?: any, data?: Record<string, any>): void;
73
+ setUser(user: Record<string, any>): void;
74
+ setTag(key: string, value: string): void;
75
+ setExtra(key: string, value: any): void;
76
+ setContext(key: string, context: Record<string, any>): void;
77
+ close(timeout?: any): Promise<boolean>;
78
+ private shouldIgnoreError(error: RouterException): boolean;
79
+ private mapSeverityToLevel(severity: string): string;
80
+ private generateFingerprint(error: RouterException): string[];
81
+ }
82
+ /**
83
+ * Bugsnag error reporter implementation
84
+ */
85
+ export declare class BugsnagReporter implements ErrorReporter {
86
+ private config: ErrorReportingConfig;
87
+ private bugsnag: any;
88
+ constructor(config: ErrorReportingConfig);
89
+ private initializeBugsnag(): Promise<void>;
90
+ report(error: RouterException, context?: ErrorContext): Promise<string | null>;
91
+ addBreadcrumb(message: string, category?: any, _level?: any, data?: Record<string, any>): void;
92
+ setUser(user: Record<string, any>): void;
93
+ setTag(key: string, value: string): void;
94
+ setExtra(key: string, value: any): void;
95
+ setContext(key: string, context: Record<string, any>): void;
96
+ close(): Promise<boolean>;
97
+ private shouldIgnoreError(error: RouterException): boolean;
98
+ private mapSeverityToBugsnag(severity: string): string;
99
+ private generateGroupingHash(error: RouterException): string;
100
+ }
101
+ /**
102
+ * Custom error reporter for custom implementations
103
+ */
104
+ export declare class CustomReporter implements ErrorReporter {
105
+ private config: ErrorReportingConfig;
106
+ private reportHandler: (report: ErrorReport) => Promise<string | null>;
107
+ constructor(config: ErrorReportingConfig, reportHandler: (report: ErrorReport) => Promise<string | null>);
108
+ report(error: RouterException, context?: ErrorContext): Promise<string | null>;
109
+ addBreadcrumb(): void;
110
+ setUser(): void;
111
+ setTag(): void;
112
+ setExtra(): void;
113
+ setContext(): void;
114
+ close(): Promise<boolean>;
115
+ private mapSeverityToLevel(severity: string): 'debug' | 'info' | 'warning' | 'error' | 'fatal';
116
+ }
117
+ /**
118
+ * Error reporting manager
119
+ */
120
+ export declare class ErrorReportingManager {
121
+ private reporters: ErrorReporter[];
122
+ private breadcrumbs: Array<{ message: string, timestamp: Date, data?: any }>;
123
+ private maxBreadcrumbs: any;
124
+ constructor(configs: ErrorReportingConfig[]);
125
+ private initializeReporters(configs: ErrorReportingConfig[]): void;
126
+ addReporter(reporter: ErrorReporter): void;
127
+ report(error: RouterException, context?: ErrorContext): Promise<string[]>;
128
+ addBreadcrumb(message: string, category?: any, data?: any): void;
129
+ setUser(user: Record<string, any>): void;
130
+ setTag(key: string, value: string): void;
131
+ setExtra(key: string, value: any): void;
132
+ setContext(key: string, context: Record<string, any>): void;
133
+ close(timeout?: any): Promise<boolean>;
134
+ getBreadcrumbs(): Array<{ message: string, timestamp: Date, data?: any }>;
135
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Factory functions for common errors
3
+ */
4
+ export declare const ErrorFactory: {
5
+ validation: (message: string, fields?: Record<string, string[]>, context?: ErrorContext) => any;
6
+ authentication: (message?: string, context?: ErrorContext) => any;
7
+ authorization: (message?: string, requiredPermissions?: string[], context?: ErrorContext) => any;
8
+ notFound: (resource?: string, resourceId?: string, context?: ErrorContext) => any;
9
+ methodNotAllowed: (method: string, allowedMethods: string[], context?: ErrorContext) => any;
10
+ timeout: (timeoutMs: number, message?: string, context?: ErrorContext) => any;
11
+ rateLimit: (retryAfter: number, limit: number, remaining?: number, context?: ErrorContext) => any;
12
+ internalServer: (message?: string, cause?: Error, context?: ErrorContext) => any;
13
+ serviceUnavailable: (message?: string, retryAfter?: number, context?: ErrorContext) => any;
14
+ database: (message: string, operation?: string, query?: string, cause?: Error, context?: ErrorContext) => any;
15
+ externalService: ( message: string, service: string, endpoint?: string, statusCode?: number, cause?: Error, context?: ErrorContext, ) => any;
16
+ circuitBreakerOpen: (service: string, nextAttemptAt: Date, context?: ErrorContext) => any;
17
+ businessLogic: (message: string, businessRule: string, context?: ErrorContext) => any;
18
+ configuration: (message: string, configKey: string, context?: ErrorContext) => any;
19
+ fileSystem: (message: string, path: string, operation: string, cause?: Error, context?: ErrorContext) => any
20
+ };
21
+ /**
22
+ * Advanced Error Handling - Exception Hierarchy
23
+ *
24
+ * Comprehensive exception types with metadata, stack traces, and context information
25
+ */
26
+ export declare interface ErrorContext {
27
+ requestId?: string
28
+ userId?: string | number
29
+ traceId?: string
30
+ spanId?: string
31
+ route?: string
32
+ method?: string
33
+ url?: string
34
+ userAgent?: string
35
+ ip?: string
36
+ timestamp?: Date
37
+ metadata?: Record<string, unknown>
38
+ }
39
+ export declare interface ErrorDetails {
40
+ code: string
41
+ message: string
42
+ context?: ErrorContext
43
+ cause?: Error
44
+ statusCode?: number
45
+ retryable?: boolean
46
+ severity?: 'low' | 'medium' | 'high' | 'critical'
47
+ category?: 'validation' | 'authentication' | 'authorization' | 'network' | 'database' | 'external' | 'system' | 'business'
48
+ }
49
+ /**
50
+ * Base exception class for all router errors
51
+ */
52
+ export declare abstract class RouterException extends Error {
53
+ readonly code: string;
54
+ readonly statusCode: number;
55
+ readonly context: ErrorContext;
56
+ readonly retryable: boolean;
57
+ readonly severity: 'low' | 'medium' | 'high' | 'critical';
58
+ readonly category: string;
59
+ readonly timestamp: Date;
60
+ readonly cause?: Error;
61
+ constructor(details: ErrorDetails);
62
+ toJSON(): Record<string, any>;
63
+ toResponse(): Response;
64
+ }
65
+ /**
66
+ * Validation errors (400)
67
+ */
68
+ export declare class ValidationException extends RouterException {
69
+ readonly fields: Record<string, string[]>;
70
+ constructor(message: string, fields?: Record<string, string[]>, context?: ErrorContext);
71
+ toResponse(): Response;
72
+ }
73
+ /**
74
+ * Authentication errors (401)
75
+ */
76
+ export declare class AuthenticationException extends RouterException {
77
+ constructor(message?: string, context?: ErrorContext);
78
+ }
79
+ /**
80
+ * Authorization errors (403)
81
+ */
82
+ export declare class AuthorizationException extends RouterException {
83
+ readonly requiredPermissions?: string[];
84
+ constructor(message?: string, requiredPermissions?: string[], context?: ErrorContext);
85
+ }
86
+ /**
87
+ * Resource not found errors (404)
88
+ */
89
+ export declare class NotFoundException extends RouterException {
90
+ readonly resource?: string;
91
+ readonly resourceId?: string;
92
+ constructor(message?: string, resource?: string, resourceId?: string, context?: ErrorContext);
93
+ }
94
+ /**
95
+ * Method not allowed errors (405)
96
+ */
97
+ export declare class MethodNotAllowedException extends RouterException {
98
+ readonly allowedMethods: string[];
99
+ constructor(method: string, allowedMethods: string[], context?: ErrorContext);
100
+ toResponse(): Response;
101
+ }
102
+ /**
103
+ * Request timeout errors (408)
104
+ */
105
+ export declare class TimeoutException extends RouterException {
106
+ readonly timeoutMs: number;
107
+ constructor(message?: string, timeoutMs: number, context?: ErrorContext);
108
+ }
109
+ /**
110
+ * Rate limit exceeded errors (429)
111
+ */
112
+ export declare class RateLimitException extends RouterException {
113
+ readonly retryAfter: number;
114
+ readonly limit: number;
115
+ readonly remaining: number;
116
+ constructor(message?: string, retryAfter: number, limit: number, remaining?: number, context?: ErrorContext);
117
+ toResponse(): Response;
118
+ }
119
+ /**
120
+ * Internal server errors (500)
121
+ */
122
+ export declare class InternalServerException extends RouterException {
123
+ constructor(message?: string, cause?: Error, context?: ErrorContext);
124
+ }
125
+ /**
126
+ * Service unavailable errors (503)
127
+ */
128
+ export declare class ServiceUnavailableException extends RouterException {
129
+ readonly retryAfter?: number;
130
+ constructor(message?: string, retryAfter?: number, context?: ErrorContext);
131
+ toResponse(): Response;
132
+ }
133
+ /**
134
+ * Database errors
135
+ */
136
+ export declare class DatabaseException extends RouterException {
137
+ readonly query?: string;
138
+ readonly operation?: string;
139
+ constructor(message: string, operation?: string, query?: string, cause?: Error, context?: ErrorContext);
140
+ }
141
+ /**
142
+ * External service errors
143
+ */
144
+ export declare class ExternalServiceException extends RouterException {
145
+ readonly service: string;
146
+ readonly endpoint?: string;
147
+ constructor(message: string, service: string, endpoint?: string, statusCode?: number, cause?: Error, context?: ErrorContext);
148
+ }
149
+ /**
150
+ * Circuit breaker open errors
151
+ */
152
+ export declare class CircuitBreakerOpenException extends RouterException {
153
+ readonly service: string;
154
+ readonly nextAttemptAt: Date;
155
+ constructor(service: string, nextAttemptAt: Date, context?: ErrorContext);
156
+ }
157
+ /**
158
+ * Business logic errors
159
+ */
160
+ export declare class BusinessLogicException extends RouterException {
161
+ readonly businessRule: string;
162
+ constructor(message: string, businessRule: string, context?: ErrorContext);
163
+ }
164
+ /**
165
+ * Configuration errors
166
+ */
167
+ export declare class ConfigurationException extends RouterException {
168
+ readonly configKey: string;
169
+ constructor(message: string, configKey: string, context?: ErrorContext);
170
+ }
171
+ /**
172
+ * File system errors
173
+ */
174
+ export declare class FileSystemException extends RouterException {
175
+ readonly path: string;
176
+ readonly operation: string;
177
+ constructor(message: string, path: string, operation: string, cause?: Error, context?: ErrorContext);
178
+ }
@@ -0,0 +1,130 @@
1
+ import type { EnhancedRequest } from '../types';
2
+ import type { ErrorContext, RouterException } from './exceptions';
3
+ /**
4
+ * Middleware for graceful degradation
5
+ */
6
+ export declare function createGracefulDegradationMiddleware(config: DegradationConfig): void;
7
+ /**
8
+ * Factory functions for common degradation strategies
9
+ */
10
+ export declare const DegradationStrategies: {
11
+ cacheFirst: (ttl: number?, staleWhileRevalidate?) => any;
12
+ staticFallback: (body: any, status?) => any;
13
+ simplifiedView: () => any;
14
+ redirectToMaintenance: (url: string) => any
15
+ };
16
+ export declare interface DegradationConfig {
17
+ enabled: boolean
18
+ fallbackStrategies: {
19
+ [serviceName: string]: FallbackStrategy
20
+ }
21
+ healthChecks: {
22
+ [serviceName: string]: HealthCheckConfig
23
+ }
24
+ monitoring: {
25
+ enabled: boolean
26
+ alertThresholds: {
27
+ errorRate: number
28
+ responseTime: number
29
+ availability: number
30
+ }
31
+ }
32
+ }
33
+ export declare interface FallbackStrategy {
34
+ type: 'cache' | 'static' | 'simplified' | 'redirect' | 'custom'
35
+ priority: number
36
+ timeout: number
37
+ retries: number
38
+ backoff: {
39
+ type: 'fixed' | 'exponential'
40
+ delay: number
41
+ maxDelay?: number
42
+ }
43
+ fallbackHandler?: (error: RouterException, context: ErrorContext) => Promise<Response>
44
+ cacheConfig?: {
45
+ key: string
46
+ ttl: number
47
+ staleWhileRevalidate: boolean
48
+ }
49
+ staticResponse?: {
50
+ status: number
51
+ body: any
52
+ headers?: Record<string, string>
53
+ }
54
+ redirectConfig?: {
55
+ url: string
56
+ permanent: boolean
57
+ }
58
+ }
59
+ export declare interface HealthCheckConfig {
60
+ enabled: boolean
61
+ endpoint: string
62
+ interval: number
63
+ timeout: number
64
+ retries: number
65
+ expectedStatus: number[]
66
+ expectedBody?: string | RegExp
67
+ headers?: Record<string, string>
68
+ onHealthy?: () => void
69
+ onUnhealthy?: (error: Error) => void
70
+ }
71
+ export declare interface ServiceHealth {
72
+ name: string
73
+ status: 'healthy' | 'degraded' | 'unhealthy'
74
+ lastCheck: Date
75
+ responseTime: number
76
+ errorRate: number
77
+ availability: number
78
+ consecutiveFailures: number
79
+ metadata?: Record<string, any>
80
+ }
81
+ export declare interface DegradationContext {
82
+ request: EnhancedRequest
83
+ serviceName: string
84
+ error: RouterException
85
+ attemptCount: number
86
+ startTime: Date
87
+ metadata?: Record<string, any>
88
+ }
89
+ /**
90
+ * Service health monitor
91
+ */
92
+ export declare class ServiceHealthMonitor {
93
+ private healthStatus: any;
94
+ private healthCheckIntervals: any;
95
+ private config: DegradationConfig;
96
+ constructor(config: DegradationConfig);
97
+ private initializeHealthChecks(): void;
98
+ private performHealthCheck(serviceName: string, config: HealthCheckConfig): Promise<void>;
99
+ private updateHealthStatus(serviceName: string, isHealthy: boolean, responseTime: number): void;
100
+ getServiceHealth(serviceName: string): ServiceHealth | undefined;
101
+ getAllServiceHealth(): ServiceHealth[];
102
+ isServiceHealthy(serviceName: string): boolean;
103
+ isServiceDegraded(serviceName: string): boolean;
104
+ stop(): void;
105
+ }
106
+ /**
107
+ * Graceful degradation manager
108
+ */
109
+ export declare class GracefulDegradationManager {
110
+ private config: DegradationConfig;
111
+ private healthMonitor: ServiceHealthMonitor;
112
+ private cache: any;
113
+ private metrics: any;
114
+ constructor(config: DegradationConfig);
115
+ handleFailure(serviceName: string, error: RouterException, request: EnhancedRequest, originalHandler: () => Promise<Response>): Promise<Response>;
116
+ private executeFallbackStrategy(strategy: FallbackStrategy, context: DegradationContext, originalHandler: () => Promise<Response>): Promise<Response>;
117
+ private handleCacheFallback(strategy: FallbackStrategy, context: DegradationContext): Promise<Response>;
118
+ private handleStaticFallback(strategy: FallbackStrategy, context: DegradationContext): Promise<Response>;
119
+ private handleSimplifiedFallback(strategy: FallbackStrategy, context: DegradationContext): Promise<Response>;
120
+ private handleRedirectFallback(strategy: FallbackStrategy, context: DegradationContext): Promise<Response>;
121
+ private handleCustomFallback(strategy: FallbackStrategy, context: DegradationContext): Promise<Response>;
122
+ cacheResponse(serviceName: string, key: string, data: any, ttl: number): void;
123
+ getServiceMetrics(serviceName: string): { errorRate: number, avgResponseTime: number, totalRequests: number };
124
+ getSystemHealth(): { status: 'healthy' | 'degraded' | 'unhealthy', services: ServiceHealth[] };
125
+ private calculateBackoffDelay(backoff: FallbackStrategy['backoff'], attempt: number): number;
126
+ private generateCacheKey(template: string, context: DegradationContext): string;
127
+ private updateMetrics(serviceName: string, success: boolean, responseTime: number): void;
128
+ private sleep(ms: number): Promise<void>;
129
+ stop(): void;
130
+ }
@@ -0,0 +1,6 @@
1
+ export * from './circuit-breaker';
2
+ export { createAdvancedErrorHandler } from './error-handler';
3
+ export * from './error-reporting';
4
+ export * from './exceptions';
5
+ export * from './graceful-degradation';
6
+ export * from './router-errors';
@@ -0,0 +1,97 @@
1
+ import { RouterException } from './exceptions';
2
+ import type { ErrorContext } from './exceptions';
3
+ /**
4
+ * Utility to find similar routes using Levenshtein distance
5
+ */
6
+ export declare function findSimilarRoutes(requestedPath: string, availableRoutes: Array<{ method: string, path: string }>, maxResults?: number): SimilarRoute[];
7
+ /**
8
+ * Detect route conflicts in a list of routes
9
+ */
10
+ export declare function detectRouteConflicts(routes: Array<{ method: string, path: string, name?: string }>): RouteConflictInfo[][];
11
+ /**
12
+ * Factory for creating router-specific errors
13
+ */
14
+ export declare const RouterErrorFactory: {
15
+ routeConflict: (routes: RouteConflictInfo[], context?: ErrorContext) => any;
16
+ circularDependency: (chain: string[], context?: ErrorContext) => any;
17
+ middlewareConfig: (name: string, errors: string[], context?: ErrorContext) => any;
18
+ routeNotFound: (method: string, path: string, similarRoutes?: SimilarRoute[], context?: ErrorContext) => any;
19
+ handlerResolution: (ref: string, reason: string, context?: ErrorContext) => any;
20
+ modelBinding: (model: string, param: string, value: string, reason: string, context?: ErrorContext) => any
21
+ };
22
+ export declare interface RouteConflictInfo {
23
+ method: string
24
+ path: string
25
+ name?: string
26
+ definedAt?: string
27
+ pattern?: string
28
+ }
29
+ export declare interface SimilarRoute {
30
+ method: string
31
+ path: string
32
+ similarity?: number
33
+ }
34
+ /**
35
+ * Route conflict error with detailed information about conflicting routes
36
+ */
37
+ export declare class RouteConflictException extends RouterException {
38
+ readonly conflictingRoutes: RouteConflictInfo[];
39
+ readonly suggestion: string;
40
+ constructor(conflictingRoutes: RouteConflictInfo[], context?: ErrorContext);
41
+ static private buildMessage(routes: RouteConflictInfo[]): string;
42
+ static private buildSuggestion(routes: RouteConflictInfo[]): string;
43
+ toJSON(): Record<string, unknown>;
44
+ }
45
+ /**
46
+ * Circular dependency error with dependency chain visualization
47
+ */
48
+ export declare class CircularDependencyException extends RouterException {
49
+ readonly dependencyChain: string[];
50
+ readonly suggestion: string;
51
+ constructor(dependencyChain: string[], context?: ErrorContext);
52
+ static private buildMessage(chain: string[]): string;
53
+ static private buildSuggestion(chain: string[]): string;
54
+ toJSON(): Record<string, unknown>;
55
+ }
56
+ /**
57
+ * Middleware configuration error
58
+ */
59
+ export declare class MiddlewareConfigurationException extends RouterException {
60
+ readonly middlewareName: string;
61
+ readonly configErrors: string[];
62
+ readonly suggestion: string;
63
+ constructor(middlewareName: string, configErrors: string[], context?: ErrorContext);
64
+ private buildSuggestion(): string;
65
+ }
66
+ /**
67
+ * Route not found error with helpful suggestions
68
+ */
69
+ export declare class RouteNotFoundException extends RouterException {
70
+ readonly requestedPath: string;
71
+ readonly requestedMethod: string;
72
+ readonly similarRoutes: SimilarRoute[];
73
+ readonly suggestion: string;
74
+ constructor(requestedMethod: string, requestedPath: string, similarRoutes?: SimilarRoute[], context?: ErrorContext);
75
+ static private buildMessage(method: string, path: string, similarRoutes: SimilarRoute[]): string;
76
+ private buildSuggestion(): string;
77
+ }
78
+ /**
79
+ * Handler resolution error
80
+ */
81
+ export declare class HandlerResolutionException extends RouterException {
82
+ readonly handlerRef: string;
83
+ readonly suggestion: string;
84
+ constructor(handlerRef: string, reason: string, context?: ErrorContext);
85
+ private buildSuggestion(handlerRef: string): string;
86
+ }
87
+ /**
88
+ * Model binding error
89
+ */
90
+ export declare class ModelBindingException extends RouterException {
91
+ readonly modelName: string;
92
+ readonly paramName: string;
93
+ readonly paramValue: string;
94
+ readonly suggestion: string;
95
+ constructor(modelName: string, paramName: string, paramValue: string, reason: string, context?: ErrorContext);
96
+ private buildSuggestion(): string;
97
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Static file middleware factory
3
+ */
4
+ export declare function createStaticFileMiddleware(config: StaticFileConfig): void;
5
+ /**
6
+ * Static file serving helpers
7
+ */
8
+ export declare const StaticFileHelpers: {
9
+ /**
10
+ * Create development server with hot reload
11
+ */
12
+ createDevelopmentServer: (config: StaticFileConfig) => any;
13
+ /**
14
+ * Create production server with aggressive caching
15
+ */
16
+ createProductionServer: (config: StaticFileConfig) => any;
17
+ /**
18
+ * Create SPA server with fallback to index.html
19
+ */
20
+ createSPAServer: (config: StaticFileConfig) => any
21
+ };
22
+ /**
23
+ * File serving utilities
24
+ */
25
+ export declare const FileServingUtils: {
26
+ /**
27
+ * Calculate optimal cache settings based on file type
28
+ */
29
+ getOptimalCacheSettings: (filePath: string) => any;
30
+ /**
31
+ * Generate security headers for static files
32
+ */
33
+ generateSecurityHeaders: () => unknown;
34
+ /**
35
+ * Create file watcher for cache invalidation
36
+ */
37
+ createFileWatcher: (server: StaticFileServer, watchPath: string) => Promise<{ close: ()
38
+ };
39
+ /**
40
+ * Static File Serving
41
+ *
42
+ * Efficient file serving using Bun.file() with advanced caching and optimization
43
+ */
44
+ export declare interface StaticFileConfig {
45
+ root: string
46
+ maxAge?: number
47
+ immutable?: boolean
48
+ etag?: boolean
49
+ lastModified?: boolean
50
+ index?: string[]
51
+ extensions?: string[]
52
+ fallthrough?: boolean
53
+ setHeaders?: (res: Response, path: string, stat: any) => void
54
+ compression?: boolean
55
+ compressionThreshold?: number
56
+ cacheControl?: string
57
+ dotfiles?: 'allow' | 'deny' | 'ignore'
58
+ }
59
+ export declare interface FileCache {
60
+ content: ArrayBuffer
61
+ etag: string
62
+ lastModified: string
63
+ mimeType: string
64
+ size: number
65
+ compressed?: ArrayBuffer
66
+ compressedEtag?: string
67
+ }
68
+ export declare interface FileStats {
69
+ hits: number
70
+ misses: number
71
+ bytesServed: number
72
+ compressionRatio: number
73
+ averageResponseTime: number
74
+ lastAccessed: number
75
+ }
76
+ /**
77
+ * High-performance static file server using Bun.file()
78
+ */
79
+ export declare class StaticFileServer {
80
+ private config: Required<StaticFileConfig>;
81
+ private cache: any;
82
+ private stats: any;
83
+ private compressionCache: any;
84
+ constructor(config: StaticFileConfig);
85
+ serve(request: Request): Promise<Response | null>;
86
+ serveFile(request: Request, filePath: string, requestPath: string): Promise<Response>;
87
+ private serveCachedFile(request: Request, cached: FileCache, requestPath: string, startTime: number): Response;
88
+ private resolveFile(pathname: string): Promise<string | null>;
89
+ private joinPath(parts: string[]): string;
90
+ private generateEtag(content: ArrayBuffer, lastModified: string): string;
91
+ private compressContent(content: ArrayBuffer): Promise<ArrayBuffer | null>;
92
+ private getMimeType(filePath: string): string;
93
+ private updateStats(path: string, bytes: number, startTime: number, cached: boolean): void;
94
+ getStats(): Record<string, FileStats>;
95
+ clearCache(): void;
96
+ getCacheSize(): number;
97
+ preloadFiles(paths: string[]): Promise<void>;
98
+ }
@@ -0,0 +1,10 @@
1
+ export { default as Auth } from './auth';
2
+ export * from './auth';
3
+ export * from './config';
4
+ export * as Errors from './errors';
5
+ export * from './middleware';
6
+ export * from './response/response-factory';
7
+ export * from './router';
8
+ export * from './testing';
9
+ export * from './types';
10
+ export * from './utils';