@stacksjs/bun-router 0.0.2 → 0.0.4

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 +7 -9
  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,57 +0,0 @@
1
- import { CircuitBreakerRegistry } from './circuit-breaker';
2
- import { ErrorReportingManager } from './error-reporting';
3
- import { GracefulDegradationManager } from './graceful-degradation';
4
- import { RouterException } from './exceptions';
5
- import type { CircuitBreakerConfig, DegradationConfig, EnhancedRequest, ErrorReportingConfig } from '../types';
6
- /**
7
- * Factory function to create advanced error handler middleware
8
- */
9
- export declare function createAdvancedErrorHandler(config?: AdvancedErrorHandlerConfig): {
10
- middleware: (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>
11
- getStats: () => { errorReporting?: any, gracefulDegradation?: any, circuitBreakers?: any }
12
- cleanup: () => Promise<void>
13
- };
14
- /**
15
- * Preset configurations for different environments
16
- */
17
- export declare const ErrorHandlerPresets: {
18
- development: () => any;
19
- production: (sentryDsn?: string, bugsnagApiKey?: string) => any;
20
- staging: (sentryDsn?: string) => any;
21
- resilient: (config: { sentryDsn?: string bugsnagApiKey?: string services?: string[] } = {}) => any
22
- };
23
- export declare interface AdvancedErrorHandlerConfig {
24
- errorReporting?: ErrorReportingConfig[]
25
- gracefulDegradation?: DegradationConfig
26
- circuitBreakers?: CircuitBreakerConfig[]
27
- globalErrorHandler?: (error: RouterException, req: EnhancedRequest) => Promise<Response>
28
- development?: boolean
29
- includeStackTrace?: boolean
30
- sanitizeErrors?: boolean
31
- logErrors?: boolean
32
- customErrorPages?: {
33
- [statusCode: number]: string | ((error: RouterException, req: EnhancedRequest) => Promise<Response>)
34
- }
35
- }
36
- /**
37
- * Advanced error handler middleware
38
- */
39
- export declare class AdvancedErrorHandler {
40
- private errorReporting?: ErrorReportingManager;
41
- private gracefulDegradation?: GracefulDegradationManager;
42
- private circuitBreakerRegistry?: CircuitBreakerRegistry;
43
- private config: AdvancedErrorHandlerConfig;
44
- constructor(config?: AdvancedErrorHandlerConfig);
45
- private initializeComponents(): void;
46
- middleware(): void;
47
- handleError(error: unknown, req: EnhancedRequest): Promise<Response>;
48
- private normalizeError(error: unknown, req: EnhancedRequest): RouterException;
49
- private createErrorResponse(error: RouterException, _req: EnhancedRequest): Response;
50
- private logError(error: RouterException, req: EnhancedRequest): void;
51
- getStats(): {
52
- errorReporting?: any
53
- gracefulDegradation?: any
54
- circuitBreakers?: any
55
- };
56
- cleanup(): Promise<void>;
57
- }
@@ -1,135 +0,0 @@
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
- }
@@ -1,178 +0,0 @@
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
- }
@@ -1,130 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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';
@@ -1,97 +0,0 @@
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
- }