@stacksjs/bun-router 0.0.13 → 0.0.14
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.
- package/CHANGELOG.md +770 -0
- package/README.md +584 -261
- package/package.json +43 -47
- package/bin/cli.ts +0 -9
- package/dist/auth.d.ts +0 -134
- package/dist/cache/lru-cache.d.ts +0 -139
- package/dist/cache/middleware-memoization.d.ts +0 -151
- package/dist/cache/route-cache-warmer.d.ts +0 -161
- package/dist/cache/sqlite-cache.d.ts +0 -209
- package/dist/cache/streaming-cache.d.ts +0 -132
- package/dist/chunk-1mvtv6jw.js +0 -13012
- package/dist/cli/colors.d.ts +0 -15
- package/dist/cli/index.d.ts +0 -10
- package/dist/cli/middleware.d.ts +0 -31
- package/dist/cli/openapi.d.ts +0 -17
- package/dist/cli/router.d.ts +0 -15
- package/dist/cli/routes.d.ts +0 -29
- package/dist/cli/utils.d.ts +0 -74
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -3195
- package/dist/config.d.ts +0 -7
- package/dist/container/container.d.ts +0 -273
- package/dist/container/contextual-binding.d.ts +0 -240
- package/dist/container/decorators.d.ts +0 -141
- package/dist/container/service-provider.d.ts +0 -285
- package/dist/development/hot-reload.d.ts +0 -187
- package/dist/development/index.d.ts +0 -167
- package/dist/development/performance-profiler.d.ts +0 -217
- package/dist/development/route-debugger.d.ts +0 -154
- package/dist/development/route-inspector.d.ts +0 -211
- package/dist/development/typescript-utilities.d.ts +0 -209
- package/dist/docs.d.ts +0 -11
- package/dist/errors/circuit-breaker.d.ts +0 -195
- package/dist/errors/error-handler.d.ts +0 -88
- package/dist/errors/error-reporting.d.ts +0 -144
- package/dist/errors/exceptions.d.ts +0 -184
- package/dist/errors/graceful-degradation.d.ts +0 -154
- package/dist/errors/index.d.ts +0 -9
- package/dist/errors/router-errors.d.ts +0 -110
- package/dist/file-serving/static-files.d.ts +0 -143
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -13933
- package/dist/middleware/auth.d.ts +0 -63
- package/dist/middleware/content_security_policy.d.ts +0 -53
- package/dist/middleware/cors.d.ts +0 -5
- package/dist/middleware/csrf.d.ts +0 -7
- package/dist/middleware/ddos_protection.d.ts +0 -39
- package/dist/middleware/file_security.d.ts +0 -26
- package/dist/middleware/file_upload.d.ts +0 -38
- package/dist/middleware/helmet.d.ts +0 -54
- package/dist/middleware/index.d.ts +0 -44
- package/dist/middleware/input_validation.d.ts +0 -45
- package/dist/middleware/json_body.d.ts +0 -4
- package/dist/middleware/performance_alerting.d.ts +0 -87
- package/dist/middleware/performance_dashboard.d.ts +0 -87
- package/dist/middleware/performance_monitor.d.ts +0 -209
- package/dist/middleware/pipeline.d.ts +0 -131
- package/dist/middleware/rate_limit.d.ts +0 -36
- package/dist/middleware/request_id.d.ts +0 -4
- package/dist/middleware/request_signing.d.ts +0 -153
- package/dist/middleware/request_tracer.d.ts +0 -72
- package/dist/middleware/response_cache.d.ts +0 -97
- package/dist/middleware/security.d.ts +0 -69
- package/dist/middleware/security_suite.d.ts +0 -46
- package/dist/middleware/session.d.ts +0 -23
- package/dist/model-binding/index.d.ts +0 -2
- package/dist/model-binding/model-middleware.d.ts +0 -118
- package/dist/model-binding/model-registry.d.ts +0 -164
- package/dist/model-binding.d.ts +0 -185
- package/dist/model-resolver-factory.d.ts +0 -31
- package/dist/observability/correlation.d.ts +0 -187
- package/dist/observability/health-checks.d.ts +0 -186
- package/dist/observability/index.d.ts +0 -60
- package/dist/observability/integration.d.ts +0 -147
- package/dist/observability/metrics.d.ts +0 -184
- package/dist/observability/tracing.d.ts +0 -187
- package/dist/optimization/bun-utilities.d.ts +0 -224
- package/dist/query-builder-integration.d.ts +0 -36
- package/dist/request/context.d.ts +0 -34
- package/dist/request/enhanced-request.d.ts +0 -213
- package/dist/request/macros.d.ts +0 -300
- package/dist/response/macros.d.ts +0 -245
- package/dist/response/response-factory.d.ts +0 -133
- package/dist/router/api-routes.d.ts +0 -5
- package/dist/router/file-based-routing.d.ts +0 -118
- package/dist/router/file-streaming.d.ts +0 -5
- package/dist/router/fluent-router.d.ts +0 -315
- package/dist/router/fluent-routing.d.ts +0 -271
- package/dist/router/group-organization.d.ts +0 -5
- package/dist/router/handler-resolver.d.ts +0 -24
- package/dist/router/http-methods.d.ts +0 -10
- package/dist/router/index.d.ts +0 -114
- package/dist/router/middleware-groups.d.ts +0 -94
- package/dist/router/middleware-integration.d.ts +0 -112
- package/dist/router/middleware.d.ts +0 -5
- package/dist/router/model-binding.d.ts +0 -5
- package/dist/router/optimized-route-matching.d.ts +0 -6
- package/dist/router/route-building.d.ts +0 -5
- package/dist/router/route-compiler.d.ts +0 -153
- package/dist/router/route-matching.d.ts +0 -5
- package/dist/router/route-trie.d.ts +0 -114
- package/dist/router/router.d.ts +0 -294
- package/dist/router/server.d.ts +0 -5
- package/dist/router/validation-integration.d.ts +0 -170
- package/dist/router/view-rendering.d.ts +0 -5
- package/dist/router/websocket.d.ts +0 -5
- package/dist/routing/route-caching.d.ts +0 -129
- package/dist/routing/route-throttling.d.ts +0 -150
- package/dist/routing/subdomain-routing.d.ts +0 -206
- package/dist/session/database-store.d.ts +0 -51
- package/dist/session/file-store.d.ts +0 -22
- package/dist/session/index.d.ts +0 -106
- package/dist/session/memory-store.d.ts +0 -21
- package/dist/session/redis-store.d.ts +0 -31
- package/dist/streaming/index.d.ts +0 -3
- package/dist/streaming/sse-handler.d.ts +0 -138
- package/dist/streaming/stream-handler.d.ts +0 -114
- package/dist/testing/auth-testing.d.ts +0 -156
- package/dist/testing/file-upload-testing.d.ts +0 -190
- package/dist/testing/index.d.ts +0 -10
- package/dist/testing/middleware-testing.d.ts +0 -138
- package/dist/testing/model-binding-testing.d.ts +0 -186
- package/dist/testing/performance-testing.d.ts +0 -235
- package/dist/testing/test-client.d.ts +0 -117
- package/dist/testing/test-request.d.ts +0 -85
- package/dist/testing/test-response.d.ts +0 -90
- package/dist/testing/types.d.ts +0 -207
- package/dist/testing/websocket-testing.d.ts +0 -227
- package/dist/types/controller-types.d.ts +0 -208
- package/dist/types/core.d.ts +0 -543
- package/dist/types/middleware-types.d.ts +0 -227
- package/dist/types/request-response-augmentation.d.ts +0 -261
- package/dist/types/route-inference.d.ts +0 -168
- package/dist/types.d.ts +0 -1782
- package/dist/url.d.ts +0 -56
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/query-preservation.d.ts +0 -48
- package/dist/utils.d.ts +0 -69
- package/dist/validation/validator.d.ts +0 -140
- package/dist/websocket/clustering.d.ts +0 -185
- package/src/auth.ts +0 -469
- package/src/cache/lru-cache.ts +0 -457
- package/src/cache/middleware-memoization.ts +0 -531
- package/src/cache/route-cache-warmer.ts +0 -486
- package/src/cache/sqlite-cache.ts +0 -783
- package/src/cache/streaming-cache.ts +0 -572
- package/src/cli/colors.ts +0 -29
- package/src/cli/index.ts +0 -287
- package/src/cli/middleware.ts +0 -291
- package/src/cli/openapi.ts +0 -407
- package/src/cli/router.ts +0 -188
- package/src/cli/routes.ts +0 -265
- package/src/cli/utils.ts +0 -531
- package/src/cli.ts +0 -5
- package/src/config.ts +0 -322
- package/src/container/container.ts +0 -740
- package/src/container/contextual-binding.ts +0 -603
- package/src/container/decorators.ts +0 -359
- package/src/container/service-provider.ts +0 -596
- package/src/development/hot-reload.ts +0 -673
- package/src/development/index.ts +0 -499
- package/src/development/performance-profiler.ts +0 -717
- package/src/development/route-debugger.ts +0 -527
- package/src/development/route-inspector.ts +0 -749
- package/src/development/typescript-utilities.ts +0 -682
- package/src/docs.ts +0 -397
- package/src/errors/circuit-breaker.ts +0 -732
- package/src/errors/error-handler.ts +0 -569
- package/src/errors/error-reporting.ts +0 -672
- package/src/errors/exceptions.ts +0 -536
- package/src/errors/graceful-degradation.ts +0 -621
- package/src/errors/index.ts +0 -21
- package/src/errors/router-errors.ts +0 -632
- package/src/file-serving/static-files.ts +0 -581
- package/src/index.ts +0 -14
- package/src/middleware/auth.ts +0 -219
- package/src/middleware/content_security_policy.ts +0 -215
- package/src/middleware/cors.ts +0 -74
- package/src/middleware/csrf.ts +0 -108
- package/src/middleware/ddos_protection.ts +0 -255
- package/src/middleware/file_security.ts +0 -191
- package/src/middleware/file_upload.ts +0 -264
- package/src/middleware/helmet.ts +0 -268
- package/src/middleware/index.ts +0 -117
- package/src/middleware/input_validation.ts +0 -449
- package/src/middleware/json_body.ts +0 -37
- package/src/middleware/performance_alerting.ts +0 -538
- package/src/middleware/performance_dashboard.ts +0 -661
- package/src/middleware/performance_monitor.ts +0 -943
- package/src/middleware/pipeline.ts +0 -489
- package/src/middleware/rate_limit.ts +0 -245
- package/src/middleware/request_id.ts +0 -36
- package/src/middleware/request_signing.ts +0 -636
- package/src/middleware/request_tracer.ts +0 -636
- package/src/middleware/response_cache.ts +0 -743
- package/src/middleware/security.ts +0 -482
- package/src/middleware/security_suite.ts +0 -257
- package/src/middleware/session.ts +0 -91
- package/src/model-binding/index.ts +0 -18
- package/src/model-binding/model-middleware.ts +0 -425
- package/src/model-binding/model-registry.ts +0 -550
- package/src/model-binding.ts +0 -370
- package/src/model-resolver-factory.ts +0 -106
- package/src/observability/correlation.ts +0 -691
- package/src/observability/health-checks.ts +0 -729
- package/src/observability/index.ts +0 -184
- package/src/observability/integration.ts +0 -548
- package/src/observability/metrics.ts +0 -753
- package/src/observability/tracing.ts +0 -638
- package/src/optimization/bun-utilities.ts +0 -778
- package/src/query-builder-integration.ts +0 -137
- package/src/request/context.ts +0 -62
- package/src/request/enhanced-request.ts +0 -857
- package/src/request/macros.ts +0 -688
- package/src/response/macros.ts +0 -612
- package/src/response/response-factory.ts +0 -596
- package/src/router/api-routes.ts +0 -243
- package/src/router/file-based-routing.ts +0 -670
- package/src/router/file-streaming.ts +0 -372
- package/src/router/fluent-router.ts +0 -927
- package/src/router/fluent-routing.ts +0 -797
- package/src/router/group-organization.ts +0 -213
- package/src/router/handler-resolver.ts +0 -291
- package/src/router/http-methods.ts +0 -377
- package/src/router/index.ts +0 -187
- package/src/router/middleware-groups.ts +0 -222
- package/src/router/middleware-integration.ts +0 -399
- package/src/router/middleware.ts +0 -231
- package/src/router/model-binding.ts +0 -215
- package/src/router/optimized-route-matching.ts +0 -253
- package/src/router/route-building.ts +0 -212
- package/src/router/route-compiler.ts +0 -702
- package/src/router/route-matching.ts +0 -349
- package/src/router/route-trie.ts +0 -464
- package/src/router/router.ts +0 -1581
- package/src/router/server.ts +0 -462
- package/src/router/validation-integration.ts +0 -443
- package/src/router/view-rendering.ts +0 -233
- package/src/router/websocket.ts +0 -100
- package/src/routing/route-caching.ts +0 -402
- package/src/routing/route-throttling.ts +0 -469
- package/src/routing/subdomain-routing.ts +0 -492
- package/src/session/database-store.ts +0 -109
- package/src/session/file-store.ts +0 -148
- package/src/session/index.ts +0 -244
- package/src/session/memory-store.ts +0 -88
- package/src/session/redis-store.ts +0 -93
- package/src/streaming/index.ts +0 -17
- package/src/streaming/sse-handler.ts +0 -482
- package/src/streaming/stream-handler.ts +0 -552
- package/src/testing/auth-testing.ts +0 -446
- package/src/testing/file-upload-testing.ts +0 -543
- package/src/testing/index.ts +0 -10
- package/src/testing/middleware-testing.ts +0 -322
- package/src/testing/model-binding-testing.ts +0 -645
- package/src/testing/performance-testing.ts +0 -738
- package/src/testing/test-client.ts +0 -310
- package/src/testing/test-request.ts +0 -315
- package/src/testing/test-response.ts +0 -332
- package/src/testing/types.ts +0 -224
- package/src/testing/websocket-testing.ts +0 -590
- package/src/types/controller-types.ts +0 -385
- package/src/types/core.ts +0 -683
- package/src/types/middleware-types.ts +0 -419
- package/src/types/request-response-augmentation.ts +0 -489
- package/src/types/route-inference.ts +0 -357
- package/src/types.ts +0 -2055
- package/src/url.ts +0 -126
- package/src/utils/index.ts +0 -1
- package/src/utils/query-preservation.ts +0 -201
- package/src/utils.ts +0 -327
- package/src/validation/validator.ts +0 -685
- package/src/websocket/clustering.ts +0 -762
package/dist/types.d.ts
DELETED
|
@@ -1,1782 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'bun';
|
|
2
|
-
import type { Router } from './router/router';
|
|
3
|
-
import type { QueryPreservationConfig } from './utils/query-preservation';
|
|
4
|
-
import type { AuthContext, AuthenticatedUser, BoundModels, CacheAdapter, CacheStats, CookieToDelete, CookieToSet, ErrorMetadata, FallbackError, FileInfo, FlashMessages, FormBody, InputValidationSchemas, InputValue, JsonBodyData, JwtHeader, JwtPayload, MetricEntry, MiddlewareParams, OAuth2Flows, OAuth2Profile, RequestContext, RequestInput, RouteMetadata, SanitizationOptions, SanitizationRule, SessionData, SessionSerializer, SessionStore, SSEConnection, StaticResponseBody, TemplateHelper, TemplateHelpers, TraceAttributes, TraceSpan, TypedServerWebSocket, User, ValidatedBody, ValidatedData, ValidationSchema, WebSocketData } from './types/core';
|
|
5
|
-
export type { QueryPreservationConfig } from './utils/query-preservation';
|
|
6
|
-
export type { AuthContext, AuthenticatedUser, BoundModels, CacheAdapter, CacheStats, CookieToDelete, CookieToSet, ErrorMetadata, FallbackError, FileInfo, FlashMessages, FormBody, InputValidationSchemas, InputValue, JsonBodyData, JwtHeader, JwtPayload, MetricEntry, MiddlewareParams, OAuth2Flows, OAuth2Profile, RequestContext, RequestInput, RouteMetadata, SanitizationOptions, SanitizationRule, SessionData, SessionSerializer, SessionStore, SSEConnection, StaticResponseBody, TemplateHelper, TemplateHelpers, TraceAttributes, TraceSpan, TypedServerWebSocket, User, ValidatedBody, ValidatedData, ValidationSchema, WebSocketData, };
|
|
7
|
-
export interface Contact {
|
|
8
|
-
name?: string;
|
|
9
|
-
email?: string;
|
|
10
|
-
url?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SecurityScheme {
|
|
13
|
-
type: 'http' | 'apiKey' | 'oauth2' | 'openIdConnect';
|
|
14
|
-
scheme?: string;
|
|
15
|
-
bearerFormat?: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
in?: 'header' | 'query' | 'cookie';
|
|
18
|
-
flows?: OAuth2Flows;
|
|
19
|
-
}
|
|
20
|
-
export interface DocsConfig {
|
|
21
|
-
output: string;
|
|
22
|
-
groupBy: 'path' | 'method' | 'tag';
|
|
23
|
-
includeExamples: boolean;
|
|
24
|
-
title: string;
|
|
25
|
-
description: string;
|
|
26
|
-
version: string;
|
|
27
|
-
baseUrl: string;
|
|
28
|
-
contact?: Contact;
|
|
29
|
-
security?: Record<string, SecurityScheme>;
|
|
30
|
-
}
|
|
31
|
-
export interface CorsConfig {
|
|
32
|
-
enabled?: boolean;
|
|
33
|
-
origin?: string | string[];
|
|
34
|
-
methods?: string[];
|
|
35
|
-
allowedHeaders?: string[];
|
|
36
|
-
exposedHeaders?: string[];
|
|
37
|
-
credentials?: boolean;
|
|
38
|
-
maxAge?: number;
|
|
39
|
-
preflightContinue?: boolean;
|
|
40
|
-
optionsSuccessStatus?: number;
|
|
41
|
-
privateNetworkAccess?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export interface RateLimitConfig {
|
|
44
|
-
enabled?: boolean;
|
|
45
|
-
max?: number;
|
|
46
|
-
timeWindow?: number;
|
|
47
|
-
message?: string;
|
|
48
|
-
draftMode?: boolean;
|
|
49
|
-
advanced?: {
|
|
50
|
-
tokensPerInterval?: number;
|
|
51
|
-
interval?: number;
|
|
52
|
-
burst?: number;
|
|
53
|
-
skipFailedRequests?: boolean;
|
|
54
|
-
keyGenerator?: (req: Request) => string;
|
|
55
|
-
algorithm?: 'fixed-window' | 'sliding-window' | 'token-bucket';
|
|
56
|
-
};
|
|
57
|
-
stores?: {
|
|
58
|
-
type: 'memory' | 'redis';
|
|
59
|
-
redis?: {
|
|
60
|
-
url: string;
|
|
61
|
-
prefix?: string;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export interface CompressionConfig {
|
|
66
|
-
enabled: boolean;
|
|
67
|
-
level: number;
|
|
68
|
-
threshold: number;
|
|
69
|
-
}
|
|
70
|
-
export interface StaticConfig {
|
|
71
|
-
enabled: boolean;
|
|
72
|
-
dir: string;
|
|
73
|
-
maxAge: number;
|
|
74
|
-
}
|
|
75
|
-
export interface CacheConfig {
|
|
76
|
-
enabled: boolean;
|
|
77
|
-
type: CacheType;
|
|
78
|
-
ttl: number;
|
|
79
|
-
max?: number;
|
|
80
|
-
redis?: {
|
|
81
|
-
url: string;
|
|
82
|
-
prefix: string;
|
|
83
|
-
maxRetries: number;
|
|
84
|
-
connectTimeout: number;
|
|
85
|
-
cluster?: {
|
|
86
|
-
nodes: string[];
|
|
87
|
-
options?: {
|
|
88
|
-
scaleReads: 'master' | 'slave' | 'all';
|
|
89
|
-
maxRedirections: number;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
customAdapter?: CacheAdapter<unknown>;
|
|
94
|
-
routeCache?: {
|
|
95
|
-
enabled: boolean;
|
|
96
|
-
ttl: number;
|
|
97
|
-
methods: string[];
|
|
98
|
-
excludePaths: string[];
|
|
99
|
-
varyByHeaders: string[];
|
|
100
|
-
varyByQuery: string[];
|
|
101
|
-
maxSize?: number;
|
|
102
|
-
purgeConditions?: {
|
|
103
|
-
maxAge: number;
|
|
104
|
-
maxItems: number;
|
|
105
|
-
lowMemory: boolean;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
strategies?: {
|
|
109
|
-
[key: string]: {
|
|
110
|
-
type: CacheStrategy;
|
|
111
|
-
ttl: number;
|
|
112
|
-
staleWhileRevalidateTtl?: number;
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
export interface PerformanceConfig {
|
|
117
|
-
cache: CacheConfig;
|
|
118
|
-
prefetch: {
|
|
119
|
-
enabled: boolean;
|
|
120
|
-
paths: string[];
|
|
121
|
-
maxConcurrent: number;
|
|
122
|
-
preloadPatterns?: string[];
|
|
123
|
-
warmupStrategy?: 'gradual' | 'aggressive';
|
|
124
|
-
prefetchHeaders?: Record<string, string>;
|
|
125
|
-
};
|
|
126
|
-
optimization: {
|
|
127
|
-
minify: boolean;
|
|
128
|
-
compress: boolean;
|
|
129
|
-
treeshake: boolean;
|
|
130
|
-
lazyLoad: boolean;
|
|
131
|
-
chunkSize: number;
|
|
132
|
-
imageOptimization?: {
|
|
133
|
-
enabled: boolean;
|
|
134
|
-
quality: number;
|
|
135
|
-
formats: ('webp' | 'avif' | 'jpeg' | 'png')[];
|
|
136
|
-
maxWidth: number;
|
|
137
|
-
responsive: boolean;
|
|
138
|
-
};
|
|
139
|
-
fontOptimization?: {
|
|
140
|
-
enabled: boolean;
|
|
141
|
-
inlineSize: number;
|
|
142
|
-
preload: boolean;
|
|
143
|
-
formats: ('woff2' | 'woff')[];
|
|
144
|
-
};
|
|
145
|
-
cssOptimization?: {
|
|
146
|
-
minify: boolean;
|
|
147
|
-
purge: boolean;
|
|
148
|
-
splitChunks: boolean;
|
|
149
|
-
criticalPath: boolean;
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
monitoring?: {
|
|
153
|
-
enabled?: boolean;
|
|
154
|
-
sampleRate?: number;
|
|
155
|
-
metrics?: {
|
|
156
|
-
responseTime?: boolean;
|
|
157
|
-
memoryUsage?: boolean;
|
|
158
|
-
cpuUsage?: boolean;
|
|
159
|
-
errorRate?: boolean;
|
|
160
|
-
requestRate?: boolean;
|
|
161
|
-
cacheStats?: boolean;
|
|
162
|
-
};
|
|
163
|
-
tracing?: {
|
|
164
|
-
enabled?: boolean;
|
|
165
|
-
sampleRate?: number;
|
|
166
|
-
serviceName?: string;
|
|
167
|
-
serviceVersion?: string;
|
|
168
|
-
environment?: string;
|
|
169
|
-
jaegerEndpoint?: string;
|
|
170
|
-
zipkinEndpoint?: string;
|
|
171
|
-
};
|
|
172
|
-
storage?: {
|
|
173
|
-
type?: CacheType;
|
|
174
|
-
maxEntries?: number;
|
|
175
|
-
filePath?: string;
|
|
176
|
-
customHandler?: (metrics: MetricEntry[]) => Promise<void>;
|
|
177
|
-
};
|
|
178
|
-
alerting?: {
|
|
179
|
-
enabled?: boolean;
|
|
180
|
-
thresholds?: {
|
|
181
|
-
responseTime?: number;
|
|
182
|
-
errorRate?: number;
|
|
183
|
-
memoryUsage?: number;
|
|
184
|
-
};
|
|
185
|
-
webhookUrl?: string;
|
|
186
|
-
slackWebhook?: string;
|
|
187
|
-
emailConfig?: {
|
|
188
|
-
smtp?: {
|
|
189
|
-
host?: string;
|
|
190
|
-
port?: number;
|
|
191
|
-
secure?: boolean;
|
|
192
|
-
auth?: {
|
|
193
|
-
user?: string;
|
|
194
|
-
pass?: string;
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
to?: string[];
|
|
198
|
-
from?: string;
|
|
199
|
-
cache: boolean;
|
|
200
|
-
queue: boolean;
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
profiling?: {
|
|
204
|
-
enabled: boolean;
|
|
205
|
-
sampleRate: number;
|
|
206
|
-
includeHeapSnapshot: boolean;
|
|
207
|
-
gcStats: boolean;
|
|
208
|
-
};
|
|
209
|
-
logging: {
|
|
210
|
-
level: 'debug' | 'info' | 'warn' | 'error';
|
|
211
|
-
format: 'json' | 'pretty';
|
|
212
|
-
destination: 'console' | 'file';
|
|
213
|
-
rotation?: {
|
|
214
|
-
size: string;
|
|
215
|
-
interval: string;
|
|
216
|
-
maxFiles: number;
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
export interface LoadBalancerConfig {
|
|
222
|
-
enabled: boolean;
|
|
223
|
-
strategy: 'round-robin' | 'least-connections' | 'ip-hash' | 'weighted-round-robin' | 'fastest-response';
|
|
224
|
-
healthCheck: {
|
|
225
|
-
enabled: boolean;
|
|
226
|
-
interval: number;
|
|
227
|
-
timeout: number;
|
|
228
|
-
unhealthyThreshold: number;
|
|
229
|
-
healthyThreshold: number;
|
|
230
|
-
path: string;
|
|
231
|
-
expectedStatus?: number;
|
|
232
|
-
expectedBody?: string;
|
|
233
|
-
headers?: Record<string, string>;
|
|
234
|
-
};
|
|
235
|
-
sticky: {
|
|
236
|
-
enabled: boolean;
|
|
237
|
-
cookieName: string;
|
|
238
|
-
ttl: number;
|
|
239
|
-
secret?: string;
|
|
240
|
-
path?: string;
|
|
241
|
-
domain?: string;
|
|
242
|
-
};
|
|
243
|
-
retries: {
|
|
244
|
-
attempts: number;
|
|
245
|
-
timeout: number;
|
|
246
|
-
codes: number[];
|
|
247
|
-
backoff?: {
|
|
248
|
-
type: 'fixed' | 'exponential' | 'fibonacci';
|
|
249
|
-
initialDelay: number;
|
|
250
|
-
maxDelay: number;
|
|
251
|
-
factor: number;
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
nodes?: {
|
|
255
|
-
[key: string]: {
|
|
256
|
-
url: string;
|
|
257
|
-
weight?: number;
|
|
258
|
-
backup?: boolean;
|
|
259
|
-
maxFails?: number;
|
|
260
|
-
failTimeout?: number;
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
export interface SecurityConfig {
|
|
265
|
-
schemes: Record<string, SecurityScheme>;
|
|
266
|
-
rateLimit: RateLimitConfig & {
|
|
267
|
-
advanced?: {
|
|
268
|
-
tokensPerInterval: number;
|
|
269
|
-
interval: number;
|
|
270
|
-
burst?: number;
|
|
271
|
-
skipFailedRequests?: boolean;
|
|
272
|
-
keyGenerator?: (req: Request) => string;
|
|
273
|
-
};
|
|
274
|
-
stores?: {
|
|
275
|
-
type: 'memory' | 'redis';
|
|
276
|
-
redis?: {
|
|
277
|
-
url: string;
|
|
278
|
-
prefix: string;
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
cors: CorsConfig & {
|
|
283
|
-
preflightContinue?: boolean;
|
|
284
|
-
optionsSuccessStatus?: number;
|
|
285
|
-
privateNetworkAccess?: boolean;
|
|
286
|
-
exposedHeaders?: string[];
|
|
287
|
-
};
|
|
288
|
-
csrf: {
|
|
289
|
-
enabled: boolean;
|
|
290
|
-
secret: string;
|
|
291
|
-
cookie: {
|
|
292
|
-
name: string;
|
|
293
|
-
options: {
|
|
294
|
-
httpOnly: boolean;
|
|
295
|
-
secure: boolean;
|
|
296
|
-
sameSite: 'strict' | 'lax' | 'none';
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
ignoreMethods?: string[];
|
|
300
|
-
ignorePaths?: string[];
|
|
301
|
-
tokenLength?: number;
|
|
302
|
-
};
|
|
303
|
-
helmet: {
|
|
304
|
-
enabled: boolean;
|
|
305
|
-
contentSecurityPolicy: boolean | {
|
|
306
|
-
directives: Record<string, string[]>;
|
|
307
|
-
reportOnly?: boolean;
|
|
308
|
-
reportUri?: string;
|
|
309
|
-
upgradeInsecureRequests?: boolean;
|
|
310
|
-
blockAllMixedContent?: boolean;
|
|
311
|
-
};
|
|
312
|
-
crossOriginEmbedderPolicy?: boolean | {
|
|
313
|
-
policy?: 'require-corp' | 'credentialless';
|
|
314
|
-
};
|
|
315
|
-
crossOriginOpenerPolicy?: boolean | {
|
|
316
|
-
policy?: 'same-origin' | 'same-origin-allow-popups' | 'unsafe-none';
|
|
317
|
-
};
|
|
318
|
-
crossOriginResourcePolicy?: boolean | {
|
|
319
|
-
policy?: 'same-site' | 'same-origin' | 'cross-origin';
|
|
320
|
-
};
|
|
321
|
-
dnsPrefetchControl?: boolean | {
|
|
322
|
-
allow?: boolean;
|
|
323
|
-
};
|
|
324
|
-
xssFilter: boolean | {
|
|
325
|
-
setOnOldIE?: boolean;
|
|
326
|
-
};
|
|
327
|
-
noSniff: boolean;
|
|
328
|
-
frameOptions: 'DENY' | 'SAMEORIGIN';
|
|
329
|
-
hidePoweredBy: boolean;
|
|
330
|
-
hsts?: {
|
|
331
|
-
maxAge: number;
|
|
332
|
-
includeSubDomains: boolean;
|
|
333
|
-
preload: boolean;
|
|
334
|
-
};
|
|
335
|
-
referrerPolicy?: string | {
|
|
336
|
-
policy?: string | string[];
|
|
337
|
-
};
|
|
338
|
-
expectCt?: {
|
|
339
|
-
enforce: boolean;
|
|
340
|
-
maxAge: number;
|
|
341
|
-
reportUri?: string;
|
|
342
|
-
};
|
|
343
|
-
ieNoOpen?: boolean;
|
|
344
|
-
originAgentCluster?: boolean;
|
|
345
|
-
permittedCrossDomainPolicies?: boolean | {
|
|
346
|
-
permittedPolicies?: 'none' | 'master-only' | 'by-content-type' | 'all';
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
ddos?: {
|
|
350
|
-
enabled?: boolean;
|
|
351
|
-
maxRequestsPerSecond?: number;
|
|
352
|
-
maxRequestsPerMinute?: number;
|
|
353
|
-
maxRequestsPerHour?: number;
|
|
354
|
-
burstLimit?: number;
|
|
355
|
-
windowSize?: number;
|
|
356
|
-
blockDuration?: number;
|
|
357
|
-
whitelistedIPs?: string[];
|
|
358
|
-
blacklistedIPs?: string[];
|
|
359
|
-
trustProxy?: boolean;
|
|
360
|
-
skipSuccessfulRequests?: boolean;
|
|
361
|
-
skipFailedRequests?: boolean;
|
|
362
|
-
keyGenerator?: (req: Request) => string;
|
|
363
|
-
store?: Extract<CacheType, 'memory' | 'redis'>;
|
|
364
|
-
redis?: {
|
|
365
|
-
url: string;
|
|
366
|
-
prefix?: string;
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
inputValidation?: {
|
|
370
|
-
enabled?: boolean;
|
|
371
|
-
sanitizeByDefault?: boolean;
|
|
372
|
-
strictMode?: boolean;
|
|
373
|
-
allowUnknownFields?: boolean;
|
|
374
|
-
maxDepth?: number;
|
|
375
|
-
schemas?: InputValidationSchemas;
|
|
376
|
-
};
|
|
377
|
-
attackPrevention?: {
|
|
378
|
-
enabled?: boolean;
|
|
379
|
-
sqlInjection?: boolean;
|
|
380
|
-
xss?: boolean;
|
|
381
|
-
pathTraversal?: boolean;
|
|
382
|
-
commandInjection?: boolean;
|
|
383
|
-
ldapInjection?: boolean;
|
|
384
|
-
xxe?: boolean;
|
|
385
|
-
customPatterns?: {
|
|
386
|
-
name: string;
|
|
387
|
-
pattern: RegExp;
|
|
388
|
-
action: 'block' | 'log' | 'sanitize';
|
|
389
|
-
}[];
|
|
390
|
-
};
|
|
391
|
-
requestFiltering?: {
|
|
392
|
-
enabled?: boolean;
|
|
393
|
-
blockSuspiciousPatterns?: boolean;
|
|
394
|
-
maxRequestsPerMinute?: number;
|
|
395
|
-
blockUserAgents?: string[];
|
|
396
|
-
allowedMethods?: string[];
|
|
397
|
-
requireUserAgent?: boolean;
|
|
398
|
-
maxBodySize?: number;
|
|
399
|
-
maxUrlLength?: number;
|
|
400
|
-
maxHeaderSize?: number;
|
|
401
|
-
allowedContentTypes?: string[];
|
|
402
|
-
};
|
|
403
|
-
ipFiltering?: {
|
|
404
|
-
enabled?: boolean;
|
|
405
|
-
whitelist?: string[];
|
|
406
|
-
blacklist?: string[];
|
|
407
|
-
blockPrivateIPs?: boolean;
|
|
408
|
-
blockCloudProviders?: boolean;
|
|
409
|
-
geoBlocking?: {
|
|
410
|
-
enabled?: boolean;
|
|
411
|
-
allowedCountries?: string[];
|
|
412
|
-
blockedCountries?: string[];
|
|
413
|
-
};
|
|
414
|
-
};
|
|
415
|
-
responseSecurity?: {
|
|
416
|
-
enabled?: boolean;
|
|
417
|
-
removeServerHeaders?: boolean;
|
|
418
|
-
addSecurityHeaders?: boolean;
|
|
419
|
-
sanitizeErrors?: boolean;
|
|
420
|
-
preventInfoDisclosure?: boolean;
|
|
421
|
-
};
|
|
422
|
-
auth: {
|
|
423
|
-
jwt: {
|
|
424
|
-
secret: string;
|
|
425
|
-
expiresIn: string;
|
|
426
|
-
algorithm: 'HS256' | 'HS384' | 'HS512' | 'RS256';
|
|
427
|
-
issuer?: string;
|
|
428
|
-
audience?: string;
|
|
429
|
-
refreshToken?: {
|
|
430
|
-
enabled: boolean;
|
|
431
|
-
expiresIn: string;
|
|
432
|
-
renewBeforeExpiry?: number;
|
|
433
|
-
};
|
|
434
|
-
rotation?: {
|
|
435
|
-
enabled: boolean;
|
|
436
|
-
interval: number;
|
|
437
|
-
maxAge: number;
|
|
438
|
-
};
|
|
439
|
-
};
|
|
440
|
-
session: {
|
|
441
|
-
enabled: boolean;
|
|
442
|
-
secret: string;
|
|
443
|
-
name: string;
|
|
444
|
-
resave: boolean;
|
|
445
|
-
rolling: boolean;
|
|
446
|
-
saveUninitialized: boolean;
|
|
447
|
-
cookie: {
|
|
448
|
-
maxAge: number;
|
|
449
|
-
secure: boolean;
|
|
450
|
-
httpOnly: boolean;
|
|
451
|
-
sameSite: 'strict' | 'lax' | 'none';
|
|
452
|
-
domain?: string;
|
|
453
|
-
path?: string;
|
|
454
|
-
};
|
|
455
|
-
store?: {
|
|
456
|
-
type: CacheType;
|
|
457
|
-
redis?: {
|
|
458
|
-
url: string;
|
|
459
|
-
prefix: string;
|
|
460
|
-
ttl?: number;
|
|
461
|
-
scanCount?: number;
|
|
462
|
-
serializer?: SessionSerializer;
|
|
463
|
-
};
|
|
464
|
-
custom?: SessionStore;
|
|
465
|
-
};
|
|
466
|
-
};
|
|
467
|
-
oauth2?: {
|
|
468
|
-
enabled: boolean;
|
|
469
|
-
providers: {
|
|
470
|
-
[key: string]: {
|
|
471
|
-
clientId: string;
|
|
472
|
-
clientSecret: string;
|
|
473
|
-
callbackURL: string;
|
|
474
|
-
scope: string[];
|
|
475
|
-
authorizationURL?: string;
|
|
476
|
-
tokenURL?: string;
|
|
477
|
-
profileURL?: string;
|
|
478
|
-
validateProfile?: (profile: OAuth2Profile) => Promise<boolean>;
|
|
479
|
-
};
|
|
480
|
-
};
|
|
481
|
-
};
|
|
482
|
-
};
|
|
483
|
-
encryption?: {
|
|
484
|
-
enabled: boolean;
|
|
485
|
-
algorithm: string;
|
|
486
|
-
key: string;
|
|
487
|
-
iv?: string;
|
|
488
|
-
encoding: 'hex' | 'base64';
|
|
489
|
-
};
|
|
490
|
-
sanitization?: {
|
|
491
|
-
enabled: boolean;
|
|
492
|
-
rules: {
|
|
493
|
-
[key: string]: {
|
|
494
|
-
type: 'escape' | 'strip' | 'validate';
|
|
495
|
-
options?: SanitizationOptions;
|
|
496
|
-
};
|
|
497
|
-
};
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
export interface ServerConfig {
|
|
501
|
-
port: number;
|
|
502
|
-
hostname: string;
|
|
503
|
-
development: boolean;
|
|
504
|
-
cors: CorsConfig;
|
|
505
|
-
rateLimit: RateLimitConfig;
|
|
506
|
-
compression: CompressionConfig;
|
|
507
|
-
static: StaticConfig;
|
|
508
|
-
performance: PerformanceConfig;
|
|
509
|
-
loadBalancer?: LoadBalancerConfig;
|
|
510
|
-
security: SecurityConfig;
|
|
511
|
-
cluster: {
|
|
512
|
-
enabled: boolean;
|
|
513
|
-
workers: number | 'auto';
|
|
514
|
-
sticky: boolean;
|
|
515
|
-
strategy?: 'rr' | 'lc';
|
|
516
|
-
maxMemory?: number;
|
|
517
|
-
restartOnMemory?: boolean;
|
|
518
|
-
ipcTimeout?: number;
|
|
519
|
-
};
|
|
520
|
-
gracefulShutdown: {
|
|
521
|
-
enabled: boolean;
|
|
522
|
-
timeout: number;
|
|
523
|
-
signals: string[];
|
|
524
|
-
forceTimeout: number;
|
|
525
|
-
preShutdown?: () => Promise<void>;
|
|
526
|
-
drain?: {
|
|
527
|
-
enabled: boolean;
|
|
528
|
-
timeout: number;
|
|
529
|
-
waitForStreams: boolean;
|
|
530
|
-
};
|
|
531
|
-
};
|
|
532
|
-
middleware: {
|
|
533
|
-
errorHandler?: (error: Error, req: Request) => Promise<Response>;
|
|
534
|
-
notFound?: (req: Request) => Promise<Response>;
|
|
535
|
-
timeout?: number;
|
|
536
|
-
order?: string[];
|
|
537
|
-
global?: MiddlewareHandler[];
|
|
538
|
-
};
|
|
539
|
-
hooks: {
|
|
540
|
-
onStart?: () => Promise<void>;
|
|
541
|
-
onStop?: () => Promise<void>;
|
|
542
|
-
onRequest?: (req: Request) => Promise<Request | Response>;
|
|
543
|
-
onResponse?: (res: Response) => Promise<Response>;
|
|
544
|
-
onError?: (error: Error) => Promise<void>;
|
|
545
|
-
onMetric?: (metric: {
|
|
546
|
-
name: string;
|
|
547
|
-
value: number;
|
|
548
|
-
tags?: Record<string, string>;
|
|
549
|
-
}) => Promise<void>;
|
|
550
|
-
onTrace?: (span: TraceSpan) => Promise<void>;
|
|
551
|
-
};
|
|
552
|
-
experimental?: {
|
|
553
|
-
http3: boolean;
|
|
554
|
-
webTransport: boolean;
|
|
555
|
-
earlyHints: boolean;
|
|
556
|
-
webSocket: {
|
|
557
|
-
enabled: boolean;
|
|
558
|
-
compression?: boolean;
|
|
559
|
-
maxPayload?: number;
|
|
560
|
-
};
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
export interface ViewEngineConfig {
|
|
564
|
-
/**
|
|
565
|
-
* The path to view files
|
|
566
|
-
*/
|
|
567
|
-
viewsPath: string;
|
|
568
|
-
/**
|
|
569
|
-
* File extensions to look for when resolving views
|
|
570
|
-
*/
|
|
571
|
-
extensions: string[];
|
|
572
|
-
/**
|
|
573
|
-
* Default layout to use for views
|
|
574
|
-
*/
|
|
575
|
-
defaultLayout?: string;
|
|
576
|
-
/**
|
|
577
|
-
* Whether to cache compiled templates
|
|
578
|
-
*/
|
|
579
|
-
cache: boolean;
|
|
580
|
-
/**
|
|
581
|
-
* Template engine to use
|
|
582
|
-
*/
|
|
583
|
-
engine: TemplateEngine;
|
|
584
|
-
/**
|
|
585
|
-
* Custom render function for template processing
|
|
586
|
-
*/
|
|
587
|
-
customRenderer?: (template: string, data: Record<string, any>, options: ViewRenderOptions) => Promise<string>;
|
|
588
|
-
/**
|
|
589
|
-
* HTML minification options
|
|
590
|
-
*/
|
|
591
|
-
minify?: {
|
|
592
|
-
enabled: boolean;
|
|
593
|
-
options?: {
|
|
594
|
-
removeComments?: boolean;
|
|
595
|
-
collapseWhitespace?: boolean;
|
|
596
|
-
conservativeCollapse?: boolean;
|
|
597
|
-
minifyJS?: boolean;
|
|
598
|
-
minifyCSS?: boolean;
|
|
599
|
-
};
|
|
600
|
-
};
|
|
601
|
-
/**
|
|
602
|
-
* Template helpers
|
|
603
|
-
*/
|
|
604
|
-
helpers?: TemplateHelpers;
|
|
605
|
-
}
|
|
606
|
-
export interface ViewRenderOptions {
|
|
607
|
-
layout?: string;
|
|
608
|
-
partials?: Record<string, string>;
|
|
609
|
-
components?: Record<string, string>;
|
|
610
|
-
helpers?: TemplateHelpers;
|
|
611
|
-
sections?: Record<string, string>;
|
|
612
|
-
}
|
|
613
|
-
export interface RouterConfig {
|
|
614
|
-
verbose: boolean;
|
|
615
|
-
routesPath?: string;
|
|
616
|
-
apiRoutesPath?: string;
|
|
617
|
-
webRoutesPath?: string;
|
|
618
|
-
apiPrefix?: string;
|
|
619
|
-
webPrefix?: string;
|
|
620
|
-
/**
|
|
621
|
-
* Base path for action handlers (default: 'actions')
|
|
622
|
-
* Used when resolving string-based handlers like 'UserAction.ts'
|
|
623
|
-
*/
|
|
624
|
-
actionsPath?: string;
|
|
625
|
-
/**
|
|
626
|
-
* Base path for controllers (default: 'controllers')
|
|
627
|
-
* Used when resolving Controller@method patterns
|
|
628
|
-
*/
|
|
629
|
-
controllersPath?: string;
|
|
630
|
-
defaultMiddleware?: {
|
|
631
|
-
api?: (string | MiddlewareHandler)[];
|
|
632
|
-
web?: (string | MiddlewareHandler)[];
|
|
633
|
-
};
|
|
634
|
-
/**
|
|
635
|
-
* View engine configuration
|
|
636
|
-
*/
|
|
637
|
-
views?: ViewEngineConfig;
|
|
638
|
-
docs?: DocsConfig;
|
|
639
|
-
server?: ServerConfig;
|
|
640
|
-
/**
|
|
641
|
-
* Query parameter preservation configuration
|
|
642
|
-
* Automatically preserves specified query parameters across navigation
|
|
643
|
-
* @example
|
|
644
|
-
* queryPreservation: {
|
|
645
|
-
* preserve: ['siteId', 'theme', 'locale'],
|
|
646
|
-
* exclude: ['_t', 'utm_source'],
|
|
647
|
-
* routes: ['/dashboard/*', '/admin/*']
|
|
648
|
-
* }
|
|
649
|
-
*/
|
|
650
|
-
queryPreservation?: QueryPreservationConfig;
|
|
651
|
-
}
|
|
652
|
-
export type RouterOptions = Partial<RouterConfig>;
|
|
653
|
-
export interface RouteParams {
|
|
654
|
-
[key: string]: string;
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Cookie map interface for working with cookies
|
|
658
|
-
*/
|
|
659
|
-
export interface CookieMap {
|
|
660
|
-
get: (name: string) => string | undefined;
|
|
661
|
-
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
662
|
-
delete: (name: string, options?: Pick<CookieOptions, 'path' | 'domain'>) => void;
|
|
663
|
-
getAll: () => Record<string, string>;
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Cookie options interface
|
|
667
|
-
*/
|
|
668
|
-
export interface CookieOptions {
|
|
669
|
-
maxAge?: number;
|
|
670
|
-
expires?: Date;
|
|
671
|
-
httpOnly?: boolean;
|
|
672
|
-
secure?: boolean;
|
|
673
|
-
path?: string;
|
|
674
|
-
domain?: string;
|
|
675
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Cookie accessor interface with utility methods
|
|
679
|
-
*/
|
|
680
|
-
export interface CookieAccessor {
|
|
681
|
-
get: (name: string) => string | undefined;
|
|
682
|
-
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
683
|
-
delete: (name: string, options?: CookieOptions) => void;
|
|
684
|
-
getAll: () => Record<string, string>;
|
|
685
|
-
}
|
|
686
|
-
export interface EnhancedRequest extends Request, Omit<RequestMacroMethods, 'ip' | 'cookies' | 'route'> {
|
|
687
|
-
/**
|
|
688
|
-
* Route parameters extracted from the URL
|
|
689
|
-
*/
|
|
690
|
-
params: Record<string, string>;
|
|
691
|
-
/**
|
|
692
|
-
* Lookup a single route param. Equivalent to `request.params[name]` but
|
|
693
|
-
* with optional default-value handling, matching the Laravel-style
|
|
694
|
-
* `$request->route('name')` ergonomics.
|
|
695
|
-
*/
|
|
696
|
-
getParam: <T = string>(name: string, defaultValue?: T) => T | undefined;
|
|
697
|
-
/**
|
|
698
|
-
* Query parameters from the URL
|
|
699
|
-
*/
|
|
700
|
-
query: Record<string, string | string[]>;
|
|
701
|
-
/**
|
|
702
|
-
* Parsed JSON body (if Content-Type is application/json)
|
|
703
|
-
*/
|
|
704
|
-
jsonBody?: Record<string, unknown>;
|
|
705
|
-
/**
|
|
706
|
-
* Form body data (if Content-Type is multipart/form-data or application/x-www-form-urlencoded)
|
|
707
|
-
*/
|
|
708
|
-
formBody?: FormBody;
|
|
709
|
-
/**
|
|
710
|
-
* Uploaded files (if Content-Type is multipart/form-data)
|
|
711
|
-
*/
|
|
712
|
-
files?: UploadedFile[];
|
|
713
|
-
/**
|
|
714
|
-
* Session data (if session middleware is used)
|
|
715
|
-
*/
|
|
716
|
-
session?: SessionData;
|
|
717
|
-
/**
|
|
718
|
-
* User data (if authentication middleware is used)
|
|
719
|
-
*/
|
|
720
|
-
user?: User;
|
|
721
|
-
/**
|
|
722
|
-
* Additional context data that can be set by middleware
|
|
723
|
-
*/
|
|
724
|
-
context?: RequestContext;
|
|
725
|
-
/**
|
|
726
|
-
* Validated data from validation middleware
|
|
727
|
-
*/
|
|
728
|
-
validated?: ValidatedData;
|
|
729
|
-
/**
|
|
730
|
-
* Model binding data
|
|
731
|
-
*/
|
|
732
|
-
models?: BoundModels;
|
|
733
|
-
/**
|
|
734
|
-
* Model binding errors
|
|
735
|
-
*/
|
|
736
|
-
modelErrors?: Record<string, string>;
|
|
737
|
-
/**
|
|
738
|
-
* Authenticated user from auth middleware
|
|
739
|
-
*/
|
|
740
|
-
auth?: AuthContext;
|
|
741
|
-
/**
|
|
742
|
-
* Rate limiting information
|
|
743
|
-
*/
|
|
744
|
-
rateLimitRemaining?: number;
|
|
745
|
-
/**
|
|
746
|
-
* Request ID for tracing
|
|
747
|
-
*/
|
|
748
|
-
requestId?: string;
|
|
749
|
-
/**
|
|
750
|
-
* IP address of the client (string property, not function from RequestMacroMethods)
|
|
751
|
-
*/
|
|
752
|
-
ip?: string;
|
|
753
|
-
/**
|
|
754
|
-
* Cookies parsed from the request with utility methods
|
|
755
|
-
*/
|
|
756
|
-
cookies?: CookieAccessor;
|
|
757
|
-
/**
|
|
758
|
-
* Flash messages (temporary messages for the next request)
|
|
759
|
-
*/
|
|
760
|
-
flash?: FlashMessages;
|
|
761
|
-
/**
|
|
762
|
-
* CSRF token
|
|
763
|
-
*/
|
|
764
|
-
csrfToken?: string;
|
|
765
|
-
/**
|
|
766
|
-
* Request start time for performance monitoring
|
|
767
|
-
*/
|
|
768
|
-
startTime?: number;
|
|
769
|
-
/**
|
|
770
|
-
* Trace ID for distributed tracing
|
|
771
|
-
*/
|
|
772
|
-
traceId?: string;
|
|
773
|
-
/**
|
|
774
|
-
* Span ID for distributed tracing
|
|
775
|
-
*/
|
|
776
|
-
spanId?: string;
|
|
777
|
-
/**
|
|
778
|
-
* Security middleware additions
|
|
779
|
-
*/
|
|
780
|
-
nonce?: string;
|
|
781
|
-
validatedBody?: ValidatedBody;
|
|
782
|
-
/**
|
|
783
|
-
* Internal cookies to set in response (used by cookie utilities)
|
|
784
|
-
*/
|
|
785
|
-
_cookiesToSet?: CookieToSet[];
|
|
786
|
-
/**
|
|
787
|
-
* Internal cookies to delete in response (used by cookie utilities)
|
|
788
|
-
*/
|
|
789
|
-
_cookiesToDelete?: CookieToDelete[];
|
|
790
|
-
/**
|
|
791
|
-
* SSE connection information
|
|
792
|
-
*/
|
|
793
|
-
sse?: SSEConnection;
|
|
794
|
-
/**
|
|
795
|
-
* The matched route object
|
|
796
|
-
*/
|
|
797
|
-
route?: Route;
|
|
798
|
-
}
|
|
799
|
-
export interface UploadedFile {
|
|
800
|
-
fieldName: string;
|
|
801
|
-
originalName: string;
|
|
802
|
-
filename: string;
|
|
803
|
-
path: string;
|
|
804
|
-
size: number;
|
|
805
|
-
mimetype: string;
|
|
806
|
-
buffer: ArrayBuffer;
|
|
807
|
-
}
|
|
808
|
-
export type RouteHandler = (_req: EnhancedRequest) => Response | Promise<Response>;
|
|
809
|
-
/**
|
|
810
|
-
* Interface for handling route actions.
|
|
811
|
-
* All action handlers must implement this interface.
|
|
812
|
-
*/
|
|
813
|
-
export interface ActionHandlerClass {
|
|
814
|
-
/**
|
|
815
|
-
* Handles an incoming HTTP request and returns a response.
|
|
816
|
-
* @param request The incoming HTTP request
|
|
817
|
-
* @returns A Promise that resolves to a Response object
|
|
818
|
-
*/
|
|
819
|
-
handle: (request: EnhancedRequest) => Promise<Response>;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Action handler path with strict pattern validation
|
|
823
|
-
*/
|
|
824
|
-
export type ActionPath = `Actions/${string}Action` | `actions/${string}Action` | `${string}Controller@${string}`;
|
|
825
|
-
/**
|
|
826
|
-
* Strongly typed action handler with better type safety
|
|
827
|
-
*/
|
|
828
|
-
export type ActionHandler<TPath extends string = string> = ActionPath | TypedRouteHandler<TPath> | RouteHandler | (new () => ActionHandlerClass) | Response;
|
|
829
|
-
/**
|
|
830
|
-
* Controller method reference with strict typing
|
|
831
|
-
*/
|
|
832
|
-
export type ControllerMethod<TController extends string = string, TMethod extends string = string> = `${TController}@${TMethod}`;
|
|
833
|
-
/**
|
|
834
|
-
* Action class constructor with typed handle method
|
|
835
|
-
*/
|
|
836
|
-
export interface TypedActionHandlerClass<TPath extends string = string> {
|
|
837
|
-
handle: (request: EnhancedRequest & {
|
|
838
|
-
params: ExtractRouteParams<TPath>;
|
|
839
|
-
}) => Promise<Response>;
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Discriminated union for different action handler types
|
|
843
|
-
*/
|
|
844
|
-
export type ActionHandlerVariant<TPath extends string = string> = {
|
|
845
|
-
type: 'path';
|
|
846
|
-
value: ActionPath;
|
|
847
|
-
} | {
|
|
848
|
-
type: 'function';
|
|
849
|
-
value: TypedRouteHandler<TPath>;
|
|
850
|
-
} | {
|
|
851
|
-
type: 'class';
|
|
852
|
-
value: new () => TypedActionHandlerClass<TPath>;
|
|
853
|
-
} | {
|
|
854
|
-
type: 'controller';
|
|
855
|
-
value: ControllerMethod;
|
|
856
|
-
};
|
|
857
|
-
export type NextFunction = () => Promise<Response | null> | Response | null;
|
|
858
|
-
export type MiddlewareHandler = (_req: EnhancedRequest, _next: NextFunction) => Promise<Response | null> | Response | null;
|
|
859
|
-
export interface Middleware {
|
|
860
|
-
handle: MiddlewareHandler;
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* Strict middleware configuration with narrow types
|
|
864
|
-
*/
|
|
865
|
-
export interface StrictMiddlewareConfig {
|
|
866
|
-
name: BuiltInMiddleware;
|
|
867
|
-
enabled: boolean;
|
|
868
|
-
priority: number;
|
|
869
|
-
timing: MiddlewareTiming;
|
|
870
|
-
params?: Record<string, string | number | boolean>;
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* Conditional middleware with narrow type constraints
|
|
874
|
-
*/
|
|
875
|
-
export interface ConditionalMiddleware<T extends BuiltInMiddleware = BuiltInMiddleware> {
|
|
876
|
-
name: T;
|
|
877
|
-
condition: (req: EnhancedRequest) => boolean;
|
|
878
|
-
handler: MiddlewareHandler;
|
|
879
|
-
priority?: number;
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Middleware group configuration with strict typing
|
|
883
|
-
*/
|
|
884
|
-
export interface MiddlewareGroup {
|
|
885
|
-
name: string;
|
|
886
|
-
middleware: (BuiltInMiddleware | MiddlewareWithParams<BuiltInMiddleware>)[];
|
|
887
|
-
priority: number;
|
|
888
|
-
description?: string;
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Throttle middleware parameters with narrow types
|
|
892
|
-
*/
|
|
893
|
-
export interface ThrottleMiddlewareParams {
|
|
894
|
-
pattern: ThrottlePattern;
|
|
895
|
-
name?: string;
|
|
896
|
-
keyGenerator?: (req: EnhancedRequest) => string;
|
|
897
|
-
skipIf?: (req: EnhancedRequest) => boolean;
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
* CORS middleware configuration with strict options
|
|
901
|
-
*/
|
|
902
|
-
export interface CorsMiddlewareConfig {
|
|
903
|
-
origin: string | string[] | boolean | ((_origin: string) => boolean);
|
|
904
|
-
methods: HTTPMethod[];
|
|
905
|
-
allowedHeaders: string[];
|
|
906
|
-
exposedHeaders?: string[];
|
|
907
|
-
credentials: boolean;
|
|
908
|
-
maxAge: number;
|
|
909
|
-
preflightContinue: boolean;
|
|
910
|
-
optionsSuccessStatus: ResponseStatus;
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Auth middleware configuration with narrow types
|
|
914
|
-
*/
|
|
915
|
-
export interface AuthMiddlewareConfig {
|
|
916
|
-
type: 'jwt' | 'session' | 'apikey' | 'basic' | 'bearer';
|
|
917
|
-
required: boolean;
|
|
918
|
-
realm?: string;
|
|
919
|
-
validateUser?: (user: User) => boolean;
|
|
920
|
-
onUnauthorized?: (req: EnhancedRequest) => Response;
|
|
921
|
-
}
|
|
922
|
-
export interface RouteGroup {
|
|
923
|
-
prefix?: string;
|
|
924
|
-
middleware?: (string | MiddlewareHandler)[];
|
|
925
|
-
}
|
|
926
|
-
export interface Route {
|
|
927
|
-
path: string;
|
|
928
|
-
handler: ActionHandler;
|
|
929
|
-
method: string;
|
|
930
|
-
middleware: MiddlewareHandler[];
|
|
931
|
-
type?: 'api' | 'web';
|
|
932
|
-
name?: string;
|
|
933
|
-
constraints?: Record<string, string> | ((_params: Record<string, string>) => boolean)[];
|
|
934
|
-
domain?: string;
|
|
935
|
-
params?: Record<string, string>;
|
|
936
|
-
pattern?: {
|
|
937
|
-
exec: (url: URL) => PatternMatchResult | null;
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* WebSocket handler configuration
|
|
942
|
-
*/
|
|
943
|
-
export interface WebSocketConfig<T extends WebSocketData = WebSocketData> {
|
|
944
|
-
open?: (ws: TypedServerWebSocket<T>) => void | Promise<void>;
|
|
945
|
-
message: (ws: TypedServerWebSocket<T>, message: string | Uint8Array | ArrayBuffer) => void | Promise<void>;
|
|
946
|
-
close?: (ws: TypedServerWebSocket<T>, code: number, reason: string) => void | Promise<void>;
|
|
947
|
-
ping?: (ws: TypedServerWebSocket<T>, data: Uint8Array) => void | Promise<void>;
|
|
948
|
-
pong?: (ws: TypedServerWebSocket<T>, data: Uint8Array) => void | Promise<void>;
|
|
949
|
-
drain?: (ws: TypedServerWebSocket<T>) => void | Promise<void>;
|
|
950
|
-
error?: (ws: TypedServerWebSocket<T>, error: Error) => void | Promise<void>;
|
|
951
|
-
maxPayloadLength?: number;
|
|
952
|
-
backpressureLimit?: number;
|
|
953
|
-
closeOnBackpressureLimit?: boolean;
|
|
954
|
-
idleTimeout?: number;
|
|
955
|
-
perMessageDeflate?: boolean | {
|
|
956
|
-
compress?: boolean | Compressor;
|
|
957
|
-
decompress?: boolean | Compressor;
|
|
958
|
-
};
|
|
959
|
-
sendPings?: boolean;
|
|
960
|
-
publishToSelf?: boolean;
|
|
961
|
-
}
|
|
962
|
-
export type Compressor = 'disable' | 'shared' | 'dedicated' | '3KB' | '4KB' | '8KB' | '16KB' | '32KB' | '64KB' | '128KB' | '256KB';
|
|
963
|
-
export interface ServerOptions<T extends WebSocketData = WebSocketData> extends Partial<Omit<Server<T>, 'websocket' | 'development'>> {
|
|
964
|
-
websocket?: WebSocketConfig<T>;
|
|
965
|
-
/**
|
|
966
|
-
* Pre-computed static responses served by Bun's native static dispatch.
|
|
967
|
-
* These bypass the fetch handler entirely for zero-allocation serving (~15% faster).
|
|
968
|
-
*/
|
|
969
|
-
static?: Record<string, Response>;
|
|
970
|
-
/**
|
|
971
|
-
* Development mode options for Bun's dev server.
|
|
972
|
-
* When true, enables HMR and development features.
|
|
973
|
-
* When an object, allows fine-grained control over HMR and console streaming.
|
|
974
|
-
*
|
|
975
|
-
* @example
|
|
976
|
-
* // Stream browser console.log/console.error to terminal
|
|
977
|
-
* development: { console: true }
|
|
978
|
-
*
|
|
979
|
-
* // Enable HMR + console streaming
|
|
980
|
-
* development: { hmr: true, console: true }
|
|
981
|
-
*/
|
|
982
|
-
development?: boolean | {
|
|
983
|
-
hmr?: boolean;
|
|
984
|
-
console?: boolean;
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Type definition for route configuration with strict typing.
|
|
989
|
-
*/
|
|
990
|
-
export interface RouteDefinition<TPath extends string = string, TMethod extends HTTPMethod = HTTPMethod, THandler extends ActionHandler = ActionHandler> {
|
|
991
|
-
/**
|
|
992
|
-
* The path pattern for the route
|
|
993
|
-
*/
|
|
994
|
-
path: TPath;
|
|
995
|
-
/**
|
|
996
|
-
* The HTTP method for the route
|
|
997
|
-
*/
|
|
998
|
-
method: TMethod;
|
|
999
|
-
/**
|
|
1000
|
-
* The action handler for the route - can be a string path, function, or class
|
|
1001
|
-
*/
|
|
1002
|
-
handler: THandler;
|
|
1003
|
-
/**
|
|
1004
|
-
* Optional array of middleware to be executed before the handler
|
|
1005
|
-
*/
|
|
1006
|
-
middleware?: (BuiltInMiddleware | MiddlewareWithParams<BuiltInMiddleware> | MiddlewareHandler)[];
|
|
1007
|
-
/**
|
|
1008
|
-
* Optional route type to distinguish between API and web routes
|
|
1009
|
-
*/
|
|
1010
|
-
type?: 'api' | 'web';
|
|
1011
|
-
/**
|
|
1012
|
-
* Optional route name for reverse routing
|
|
1013
|
-
*/
|
|
1014
|
-
name?: string;
|
|
1015
|
-
/**
|
|
1016
|
-
* Route parameter constraints
|
|
1017
|
-
*/
|
|
1018
|
-
constraints?: {
|
|
1019
|
-
[K in keyof ExtractRouteParams<TPath>]: RouteConstraint;
|
|
1020
|
-
};
|
|
1021
|
-
/**
|
|
1022
|
-
* Optional route metadata for documentation or other purposes
|
|
1023
|
-
*/
|
|
1024
|
-
meta?: RouteMetadata;
|
|
1025
|
-
/**
|
|
1026
|
-
* Cache configuration for this specific route
|
|
1027
|
-
*/
|
|
1028
|
-
cache?: {
|
|
1029
|
-
enabled: boolean;
|
|
1030
|
-
ttl: number;
|
|
1031
|
-
tags?: string[];
|
|
1032
|
-
strategy?: CacheStrategy;
|
|
1033
|
-
};
|
|
1034
|
-
/**
|
|
1035
|
-
* Rate limiting configuration for this route
|
|
1036
|
-
*/
|
|
1037
|
-
throttle?: ThrottlePattern | ThrottleMiddlewareParams;
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* HTTP Methods type - extremely narrow
|
|
1041
|
-
*/
|
|
1042
|
-
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'TRACE' | 'CONNECT';
|
|
1043
|
-
/**
|
|
1044
|
-
* Narrow throttle pattern types
|
|
1045
|
-
*/
|
|
1046
|
-
export type ThrottlePattern = `${number}` | `${number},${number}` | `${number},${number}min` | `${number},${number}m` | `${number},${number}sec` | `${number},${number}s` | `${number},${number}hour` | `${number},${number}h`;
|
|
1047
|
-
/**
|
|
1048
|
-
* Cache strategy types - narrow and specific
|
|
1049
|
-
*/
|
|
1050
|
-
export type CacheStrategy = 'stale-while-revalidate' | 'cache-first' | 'network-first';
|
|
1051
|
-
/**
|
|
1052
|
-
* Cache type narrow definition
|
|
1053
|
-
*/
|
|
1054
|
-
export type CacheType = 'memory' | 'redis' | 'custom';
|
|
1055
|
-
/**
|
|
1056
|
-
* File extension types for views
|
|
1057
|
-
*/
|
|
1058
|
-
export type ViewExtension = '.html' | '.stx' | '.hbs' | '.ejs' | '.pug' | '.mustache';
|
|
1059
|
-
/**
|
|
1060
|
-
* Template engine types
|
|
1061
|
-
*/
|
|
1062
|
-
export type TemplateEngine = 'auto' | 'stx' | 'html' | 'handlebars' | 'ejs' | 'pug' | 'mustache' | 'custom';
|
|
1063
|
-
/**
|
|
1064
|
-
* Route parameter constraint patterns
|
|
1065
|
-
*/
|
|
1066
|
-
export type RouteConstraint = 'number' | 'alpha' | 'alphanumeric' | 'uuid' | 'slug' | RegExp | string;
|
|
1067
|
-
/**
|
|
1068
|
-
* Middleware execution timing
|
|
1069
|
-
*/
|
|
1070
|
-
export type MiddlewareTiming = 'before' | 'after' | 'around';
|
|
1071
|
-
/**
|
|
1072
|
-
* Security header types
|
|
1073
|
-
*/
|
|
1074
|
-
export type SecurityHeader = 'Content-Security-Policy' | 'X-Frame-Options' | 'X-Content-Type-Options' | 'Referrer-Policy' | 'Permissions-Policy' | 'Strict-Transport-Security';
|
|
1075
|
-
/**
|
|
1076
|
-
* Built-in middleware names - extremely narrow
|
|
1077
|
-
*/
|
|
1078
|
-
export type BuiltInMiddleware = 'auth' | 'cors' | 'csrf' | 'helmet' | 'json' | 'compress' | 'static' | 'session' | 'rateLimiter' | 'requestId' | 'logger' | 'throttle';
|
|
1079
|
-
/**
|
|
1080
|
-
* Middleware with parameters
|
|
1081
|
-
*/
|
|
1082
|
-
export type MiddlewareWithParams<T extends string = string> = T | `${T}:${string}`;
|
|
1083
|
-
/**
|
|
1084
|
-
* Route path parameter types - narrow template literals
|
|
1085
|
-
*/
|
|
1086
|
-
export type RouteParam<T extends string> = T extends `{${infer P}}` ? P : never;
|
|
1087
|
-
/**
|
|
1088
|
-
* Extract parameters from route path
|
|
1089
|
-
*/
|
|
1090
|
-
export type ExtractRouteParams<T extends string> = T extends `${string}{${infer Param}}${infer Rest}` ? {
|
|
1091
|
-
[K in Param]: string;
|
|
1092
|
-
} & ExtractRouteParams<Rest> : object;
|
|
1093
|
-
/**
|
|
1094
|
-
* Route method constraints
|
|
1095
|
-
*/
|
|
1096
|
-
export type RouteMethodConstraint<M extends HTTPMethod = HTTPMethod> = M;
|
|
1097
|
-
/**
|
|
1098
|
-
* File MIME types for uploads
|
|
1099
|
-
*/
|
|
1100
|
-
export type AllowedMimeType = 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'image/svg+xml' | 'application/pdf' | 'application/json' | 'text/plain' | 'text/csv' | 'application/octet-stream';
|
|
1101
|
-
/**
|
|
1102
|
-
* Response status codes - narrow and specific
|
|
1103
|
-
*/
|
|
1104
|
-
export type ResponseStatus = 200 | 201 | 202 | 204 | 301 | 302 | 304 | 400 | 401 | 403 | 404 | 405 | 409 | 422 | 429 | 500 | 502 | 503 | 504;
|
|
1105
|
-
/**
|
|
1106
|
-
* Content types - narrow
|
|
1107
|
-
*/
|
|
1108
|
-
export type ContentType = 'application/json' | 'application/xml' | 'text/html' | 'text/plain' | 'text/csv' | 'application/pdf' | 'application/octet-stream' | 'multipart/form-data' | 'application/x-www-form-urlencoded';
|
|
1109
|
-
/**
|
|
1110
|
-
* Strongly typed route method signatures
|
|
1111
|
-
*/
|
|
1112
|
-
export interface TypedRouteHandler<TPath extends string> {
|
|
1113
|
-
(req: EnhancedRequest & {
|
|
1114
|
-
params: ExtractRouteParams<TPath>;
|
|
1115
|
-
}): Response | Promise<Response>;
|
|
1116
|
-
}
|
|
1117
|
-
/**
|
|
1118
|
-
* Strongly typed route definition for specific HTTP methods
|
|
1119
|
-
*/
|
|
1120
|
-
export interface GetRoute<TPath extends string> extends RouteDefinition<TPath, 'GET'> {
|
|
1121
|
-
method: 'GET';
|
|
1122
|
-
handler: TypedRouteHandler<TPath> | ActionHandler;
|
|
1123
|
-
}
|
|
1124
|
-
export interface PostRoute<TPath extends string> extends RouteDefinition<TPath, 'POST'> {
|
|
1125
|
-
method: 'POST';
|
|
1126
|
-
handler: TypedRouteHandler<TPath> | ActionHandler;
|
|
1127
|
-
}
|
|
1128
|
-
export interface PutRoute<TPath extends string> extends RouteDefinition<TPath, 'PUT'> {
|
|
1129
|
-
method: 'PUT';
|
|
1130
|
-
handler: TypedRouteHandler<TPath> | ActionHandler;
|
|
1131
|
-
}
|
|
1132
|
-
export interface DeleteRoute<TPath extends string> extends RouteDefinition<TPath, 'DELETE'> {
|
|
1133
|
-
method: 'DELETE';
|
|
1134
|
-
handler: TypedRouteHandler<TPath> | ActionHandler;
|
|
1135
|
-
}
|
|
1136
|
-
export interface PatchRoute<TPath extends string> extends RouteDefinition<TPath, 'PATCH'> {
|
|
1137
|
-
method: 'PATCH';
|
|
1138
|
-
handler: TypedRouteHandler<TPath> | ActionHandler;
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Union of all typed route definitions
|
|
1142
|
-
*/
|
|
1143
|
-
export type TypedRouteDefinition<TPath extends string = string> = GetRoute<TPath> | PostRoute<TPath> | PutRoute<TPath> | DeleteRoute<TPath> | PatchRoute<TPath>;
|
|
1144
|
-
/**
|
|
1145
|
-
* Route validation helpers
|
|
1146
|
-
*/
|
|
1147
|
-
export interface RouteValidation<TPath extends string> {
|
|
1148
|
-
path: TPath;
|
|
1149
|
-
params: ExtractRouteParams<TPath>;
|
|
1150
|
-
validate: (req: EnhancedRequest) => req is EnhancedRequest & {
|
|
1151
|
-
params: ExtractRouteParams<TPath>;
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Common route patterns with strict template literal types
|
|
1156
|
-
*/
|
|
1157
|
-
export type CommonRoutePatterns = '/' | '/health' | '/api' | '/api/v1' | '/api/v1/users' | '/api/v1/users/{id}' | '/api/v1/users/{userId}/posts' | '/api/v1/users/{userId}/posts/{postId}' | '/admin' | '/admin/{section}' | '/auth/login' | '/auth/logout' | '/auth/register' | '/auth/forgot-password' | '/uploads/{filename}' | '/assets/{path}';
|
|
1158
|
-
/**
|
|
1159
|
-
* RESTful resource route patterns
|
|
1160
|
-
*/
|
|
1161
|
-
export type ResourceRoutePatterns<T extends string> = `/${T}` | `/${T}/{id}` | `/${T}/create` | `/${T}/{id}/edit` | `/${T}/{id}/show`;
|
|
1162
|
-
/**
|
|
1163
|
-
* API versioning patterns
|
|
1164
|
-
*/
|
|
1165
|
-
export type ApiVersionPattern<V extends string, Path extends string> = `/api/${V}${Path}`;
|
|
1166
|
-
/**
|
|
1167
|
-
* Nested resource patterns
|
|
1168
|
-
*/
|
|
1169
|
-
export type NestedResourcePattern<Parent extends string, Child extends string, ParentId extends string = 'id', ChildId extends string = 'id'> = `/${Parent}/{${ParentId}}/${Child}` | `/${Parent}/{${ParentId}}/${Child}/{${ChildId}}`;
|
|
1170
|
-
/**
|
|
1171
|
-
* Route parameter patterns with constraints
|
|
1172
|
-
*/
|
|
1173
|
-
export type IdPattern = '{id}';
|
|
1174
|
-
export type UuidPattern = '{uuid}';
|
|
1175
|
-
export type SlugPattern = '{slug}';
|
|
1176
|
-
export type NumberPattern = '{number}';
|
|
1177
|
-
/**
|
|
1178
|
-
* File path patterns
|
|
1179
|
-
*/
|
|
1180
|
-
export type FilePathPattern = '{filepath}' | '{*filepath}' | '{path...}';
|
|
1181
|
-
/**
|
|
1182
|
-
* Discriminated union for cache configurations
|
|
1183
|
-
*/
|
|
1184
|
-
export type CacheConfigVariant = {
|
|
1185
|
-
type: 'memory';
|
|
1186
|
-
maxSize: number;
|
|
1187
|
-
ttl: number;
|
|
1188
|
-
} | {
|
|
1189
|
-
type: 'redis';
|
|
1190
|
-
url: string;
|
|
1191
|
-
prefix: string;
|
|
1192
|
-
ttl: number;
|
|
1193
|
-
maxRetries: number;
|
|
1194
|
-
} | {
|
|
1195
|
-
type: 'custom';
|
|
1196
|
-
adapter: CacheConfig['customAdapter'];
|
|
1197
|
-
ttl: number;
|
|
1198
|
-
};
|
|
1199
|
-
/**
|
|
1200
|
-
* Discriminated union for authentication configurations
|
|
1201
|
-
*/
|
|
1202
|
-
export type AuthConfigVariant = {
|
|
1203
|
-
type: 'jwt';
|
|
1204
|
-
secret: string;
|
|
1205
|
-
expiresIn: string;
|
|
1206
|
-
algorithm: 'HS256' | 'HS384' | 'HS512' | 'RS256';
|
|
1207
|
-
} | {
|
|
1208
|
-
type: 'session';
|
|
1209
|
-
secret: string;
|
|
1210
|
-
store: CacheType;
|
|
1211
|
-
maxAge: number;
|
|
1212
|
-
} | {
|
|
1213
|
-
type: 'apikey';
|
|
1214
|
-
keyName: string;
|
|
1215
|
-
location: 'header' | 'query' | 'cookie';
|
|
1216
|
-
} | {
|
|
1217
|
-
type: 'basic';
|
|
1218
|
-
realm: string;
|
|
1219
|
-
users: Record<string, string>;
|
|
1220
|
-
} | {
|
|
1221
|
-
type: 'bearer';
|
|
1222
|
-
validate: (token: string) => Promise<boolean>;
|
|
1223
|
-
};
|
|
1224
|
-
/**
|
|
1225
|
-
* Discriminated union for rate limiting configurations
|
|
1226
|
-
*/
|
|
1227
|
-
export type RateLimitConfigVariant = {
|
|
1228
|
-
type: 'memory';
|
|
1229
|
-
maxAttempts: number;
|
|
1230
|
-
windowMs: number;
|
|
1231
|
-
keyGenerator?: (req: EnhancedRequest) => string;
|
|
1232
|
-
} | {
|
|
1233
|
-
type: 'redis';
|
|
1234
|
-
maxAttempts: number;
|
|
1235
|
-
windowMs: number;
|
|
1236
|
-
redisUrl: string;
|
|
1237
|
-
keyPrefix: string;
|
|
1238
|
-
} | {
|
|
1239
|
-
type: 'pattern';
|
|
1240
|
-
pattern: ThrottlePattern;
|
|
1241
|
-
name?: string;
|
|
1242
|
-
};
|
|
1243
|
-
/**
|
|
1244
|
-
* Discriminated union for middleware configurations
|
|
1245
|
-
*/
|
|
1246
|
-
export type MiddlewareConfigVariant = {
|
|
1247
|
-
type: 'throttle';
|
|
1248
|
-
config: RateLimitConfigVariant;
|
|
1249
|
-
} | {
|
|
1250
|
-
type: 'cors';
|
|
1251
|
-
config: CorsMiddlewareConfig;
|
|
1252
|
-
} | {
|
|
1253
|
-
type: 'auth';
|
|
1254
|
-
config: AuthConfigVariant;
|
|
1255
|
-
} | {
|
|
1256
|
-
type: 'cache';
|
|
1257
|
-
config: CacheConfigVariant;
|
|
1258
|
-
} | {
|
|
1259
|
-
type: 'custom';
|
|
1260
|
-
name: string;
|
|
1261
|
-
handler: MiddlewareHandler;
|
|
1262
|
-
params?: MiddlewareParams;
|
|
1263
|
-
};
|
|
1264
|
-
/**
|
|
1265
|
-
* Discriminated union for route handlers
|
|
1266
|
-
*/
|
|
1267
|
-
export type RouteHandlerVariant<TPath extends string = string> = {
|
|
1268
|
-
type: 'action';
|
|
1269
|
-
path: ActionPath;
|
|
1270
|
-
} | {
|
|
1271
|
-
type: 'function';
|
|
1272
|
-
handler: TypedRouteHandler<TPath>;
|
|
1273
|
-
} | {
|
|
1274
|
-
type: 'class';
|
|
1275
|
-
constructor: new () => TypedActionHandlerClass<TPath>;
|
|
1276
|
-
} | {
|
|
1277
|
-
type: 'controller';
|
|
1278
|
-
method: ControllerMethod;
|
|
1279
|
-
};
|
|
1280
|
-
/**
|
|
1281
|
-
* Discriminated union for validation rules
|
|
1282
|
-
*/
|
|
1283
|
-
export type ValidationRuleVariant = {
|
|
1284
|
-
type: 'required';
|
|
1285
|
-
message?: string;
|
|
1286
|
-
} | {
|
|
1287
|
-
type: 'string';
|
|
1288
|
-
minLength?: number;
|
|
1289
|
-
maxLength?: number;
|
|
1290
|
-
pattern?: RegExp;
|
|
1291
|
-
} | {
|
|
1292
|
-
type: 'number';
|
|
1293
|
-
min?: number;
|
|
1294
|
-
max?: number;
|
|
1295
|
-
integer?: boolean;
|
|
1296
|
-
} | {
|
|
1297
|
-
type: 'email';
|
|
1298
|
-
message?: string;
|
|
1299
|
-
} | {
|
|
1300
|
-
type: 'url';
|
|
1301
|
-
protocols?: string[];
|
|
1302
|
-
} | {
|
|
1303
|
-
type: 'custom';
|
|
1304
|
-
validate: (value: unknown) => boolean | Promise<boolean>;
|
|
1305
|
-
message: string;
|
|
1306
|
-
};
|
|
1307
|
-
/**
|
|
1308
|
-
* Streaming configuration types with extreme narrowing
|
|
1309
|
-
*/
|
|
1310
|
-
export type StreamingFormat = 'json' | 'ndjson' | 'csv' | 'xml' | 'text' | 'binary';
|
|
1311
|
-
export type StreamingCompression = 'gzip' | 'deflate' | 'br' | 'none';
|
|
1312
|
-
export type StreamingMode = 'chunked' | 'buffered' | 'direct';
|
|
1313
|
-
/**
|
|
1314
|
-
* Server-Sent Events configuration
|
|
1315
|
-
*/
|
|
1316
|
-
export interface SSEConfig {
|
|
1317
|
-
retryInterval?: number;
|
|
1318
|
-
keepAlive?: number;
|
|
1319
|
-
compression?: StreamingCompression;
|
|
1320
|
-
maxConnections?: number;
|
|
1321
|
-
heartbeatInterval?: number;
|
|
1322
|
-
headers?: Record<string, string>;
|
|
1323
|
-
enableHeartbeat?: boolean;
|
|
1324
|
-
connectionTimeout?: number;
|
|
1325
|
-
retryDelay?: number;
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* SSE Event data structure with strict typing
|
|
1329
|
-
*/
|
|
1330
|
-
export interface SSEEvent<T = unknown> {
|
|
1331
|
-
data: T;
|
|
1332
|
-
event?: string;
|
|
1333
|
-
id?: string | number;
|
|
1334
|
-
retry?: number;
|
|
1335
|
-
comment?: string;
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* Stream generator function types
|
|
1339
|
-
*/
|
|
1340
|
-
export type SSEGenerator<T = unknown> = () => AsyncGenerator<SSEEvent<T>, void, unknown>;
|
|
1341
|
-
/**
|
|
1342
|
-
* Direct streaming configuration
|
|
1343
|
-
*/
|
|
1344
|
-
export interface DirectStreamConfig {
|
|
1345
|
-
headers?: Record<string, string>;
|
|
1346
|
-
status?: ResponseStatus;
|
|
1347
|
-
compression?: StreamingCompression;
|
|
1348
|
-
format?: StreamingFormat;
|
|
1349
|
-
bufferSize?: number;
|
|
1350
|
-
delimiter?: string;
|
|
1351
|
-
contentType?: ContentType;
|
|
1352
|
-
enableCompression?: boolean;
|
|
1353
|
-
compressionType?: StreamingCompression;
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* Buffered streaming configuration
|
|
1357
|
-
*/
|
|
1358
|
-
export interface BufferedStreamConfig extends DirectStreamConfig {
|
|
1359
|
-
highWaterMark?: number;
|
|
1360
|
-
maxBuffer?: number;
|
|
1361
|
-
flushInterval?: number;
|
|
1362
|
-
autoFlush?: boolean;
|
|
1363
|
-
contentType?: ContentType;
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* File streaming configuration with strict types
|
|
1367
|
-
*/
|
|
1368
|
-
export interface FileStreamConfig {
|
|
1369
|
-
headers?: Record<string, string>;
|
|
1370
|
-
status?: ResponseStatus;
|
|
1371
|
-
mimeType?: AllowedMimeType;
|
|
1372
|
-
disposition?: 'inline' | 'attachment';
|
|
1373
|
-
filename?: string;
|
|
1374
|
-
maxAge?: number;
|
|
1375
|
-
etag?: boolean;
|
|
1376
|
-
lastModified?: boolean;
|
|
1377
|
-
compression?: StreamingCompression;
|
|
1378
|
-
}
|
|
1379
|
-
/**
|
|
1380
|
-
* Range request configuration for file streaming
|
|
1381
|
-
*/
|
|
1382
|
-
export interface RangeStreamConfig extends FileStreamConfig {
|
|
1383
|
-
unit?: 'bytes';
|
|
1384
|
-
maxRanges?: number;
|
|
1385
|
-
enableMultipart?: boolean;
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Transform stream configuration
|
|
1389
|
-
*/
|
|
1390
|
-
export interface TransformStreamConfig<TInput = any, TOutput = any> {
|
|
1391
|
-
transform: (chunk: TInput) => TOutput | Promise<TOutput>;
|
|
1392
|
-
flush?: () => TOutput[] | Promise<TOutput[]>;
|
|
1393
|
-
objectMode?: boolean;
|
|
1394
|
-
highWaterMark?: number;
|
|
1395
|
-
format?: StreamingFormat;
|
|
1396
|
-
headers?: Record<string, string>;
|
|
1397
|
-
}
|
|
1398
|
-
/**
|
|
1399
|
-
* Streaming response writer interfaces
|
|
1400
|
-
*/
|
|
1401
|
-
export interface StreamWriter<T = any> {
|
|
1402
|
-
write: (chunk: T) => void | Promise<void>;
|
|
1403
|
-
end: () => void | Promise<void>;
|
|
1404
|
-
close: () => void;
|
|
1405
|
-
}
|
|
1406
|
-
export interface BufferedStreamWriterGeneric<T = any> extends StreamWriter<T> {
|
|
1407
|
-
flush: () => void | Promise<void>;
|
|
1408
|
-
cork: () => void;
|
|
1409
|
-
uncork: () => void;
|
|
1410
|
-
}
|
|
1411
|
-
/**
|
|
1412
|
-
* Model binding configuration with strict types
|
|
1413
|
-
*/
|
|
1414
|
-
export interface ModelBinding<T = any> {
|
|
1415
|
-
name: string;
|
|
1416
|
-
model: string;
|
|
1417
|
-
parameter: string;
|
|
1418
|
-
required?: boolean;
|
|
1419
|
-
as?: string;
|
|
1420
|
-
resolver: ModelResolver<T>;
|
|
1421
|
-
cache?: {
|
|
1422
|
-
enabled: boolean;
|
|
1423
|
-
ttl: number;
|
|
1424
|
-
key?: (params: Record<string, string>) => string;
|
|
1425
|
-
};
|
|
1426
|
-
validation?: {
|
|
1427
|
-
required?: boolean;
|
|
1428
|
-
validator?: (model: T) => boolean | Promise<boolean>;
|
|
1429
|
-
};
|
|
1430
|
-
errorHandler?: (error: Error, params: Record<string, string>) => Response;
|
|
1431
|
-
}
|
|
1432
|
-
/**
|
|
1433
|
-
* Model resolver function type
|
|
1434
|
-
*/
|
|
1435
|
-
export type ModelResolver<T = any> = (params: Record<string, string>, req: EnhancedRequest) => T | Promise<T> | null;
|
|
1436
|
-
/**
|
|
1437
|
-
* Model validator function type
|
|
1438
|
-
*/
|
|
1439
|
-
export type ModelValidatorFn<T = any> = (model: T, params: Record<string, string>, req?: EnhancedRequest) => Promise<{
|
|
1440
|
-
valid: boolean;
|
|
1441
|
-
error?: string;
|
|
1442
|
-
status?: number;
|
|
1443
|
-
}> | {
|
|
1444
|
-
valid: boolean;
|
|
1445
|
-
error?: string;
|
|
1446
|
-
status?: number;
|
|
1447
|
-
};
|
|
1448
|
-
/**
|
|
1449
|
-
* Model transformer function type
|
|
1450
|
-
*/
|
|
1451
|
-
export type ModelTransformerFn<T = any> = (model: T, params?: Record<string, string>, req?: EnhancedRequest) => any | Promise<any>;
|
|
1452
|
-
/**
|
|
1453
|
-
* Model registry interface
|
|
1454
|
-
*/
|
|
1455
|
-
export interface ModelRegistry {
|
|
1456
|
-
register: <T>(binding: ModelBinding<T>) => void;
|
|
1457
|
-
resolve: <T>(name: string, params: Record<string, string>, req: EnhancedRequest) => Promise<T | null>;
|
|
1458
|
-
has: (name: string) => boolean;
|
|
1459
|
-
clear: () => void;
|
|
1460
|
-
getAll: () => ModelBinding[];
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Model binding middleware configuration
|
|
1464
|
-
*/
|
|
1465
|
-
export interface ModelBindingConfig {
|
|
1466
|
-
parameterName: string;
|
|
1467
|
-
modelName: string;
|
|
1468
|
-
required?: boolean;
|
|
1469
|
-
cacheKey?: (params: Record<string, string>) => string;
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Resource route configuration with model binding
|
|
1473
|
-
*/
|
|
1474
|
-
export interface ResourceConfig {
|
|
1475
|
-
controller: string;
|
|
1476
|
-
only?: ('index' | 'show' | 'create' | 'store' | 'edit' | 'update' | 'destroy')[];
|
|
1477
|
-
except?: ('index' | 'show' | 'create' | 'store' | 'edit' | 'update' | 'destroy')[];
|
|
1478
|
-
middleware?: (BuiltInMiddleware | MiddlewareWithParams<BuiltInMiddleware>)[];
|
|
1479
|
-
bindings?: Record<string, string>;
|
|
1480
|
-
names?: Partial<Record<'index' | 'show' | 'create' | 'store' | 'edit' | 'update' | 'destroy', string>>;
|
|
1481
|
-
}
|
|
1482
|
-
/**
|
|
1483
|
-
* Stream route handler with typed path parameters
|
|
1484
|
-
*/
|
|
1485
|
-
export interface StreamRouteHandler<TPath extends string = string> {
|
|
1486
|
-
(req: EnhancedRequest & {
|
|
1487
|
-
params: ExtractRouteParams<TPath>;
|
|
1488
|
-
}, writer: StreamWriter): Promise<void> | void;
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* SSE route handler with typed path parameters
|
|
1492
|
-
*/
|
|
1493
|
-
export interface SSERouteHandler<TPath extends string = string> {
|
|
1494
|
-
(req: EnhancedRequest & {
|
|
1495
|
-
params: ExtractRouteParams<TPath>;
|
|
1496
|
-
}): SSEGenerator | AsyncGenerator<SSEEvent, void, unknown>;
|
|
1497
|
-
}
|
|
1498
|
-
/**
|
|
1499
|
-
* Route matching result
|
|
1500
|
-
*/
|
|
1501
|
-
export interface MatchResult {
|
|
1502
|
-
route: Route;
|
|
1503
|
-
params: Record<string, string>;
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* URL pattern match result
|
|
1507
|
-
*/
|
|
1508
|
-
export interface PatternMatchResult {
|
|
1509
|
-
pathname: {
|
|
1510
|
-
groups: Record<string, string>;
|
|
1511
|
-
};
|
|
1512
|
-
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Streaming response options
|
|
1515
|
-
*/
|
|
1516
|
-
export interface StreamingOptions {
|
|
1517
|
-
headers?: Record<string, string>;
|
|
1518
|
-
status?: number;
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* SSE (Server-Sent Events) data structure
|
|
1522
|
-
*/
|
|
1523
|
-
export interface SSEData {
|
|
1524
|
-
data: any;
|
|
1525
|
-
event?: string;
|
|
1526
|
-
id?: string;
|
|
1527
|
-
retry?: number;
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Direct streaming writer interface
|
|
1531
|
-
*/
|
|
1532
|
-
export interface DirectStreamWriter {
|
|
1533
|
-
write: (chunk: string | Uint8Array) => void;
|
|
1534
|
-
close: () => void;
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
* Buffered streaming writer interface
|
|
1538
|
-
*/
|
|
1539
|
-
export interface BufferedStreamWriter {
|
|
1540
|
-
write: (chunk: string | Uint8Array) => void;
|
|
1541
|
-
flush: () => void;
|
|
1542
|
-
end: () => void;
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Buffered streaming options
|
|
1546
|
-
*/
|
|
1547
|
-
export interface BufferedStreamOptions {
|
|
1548
|
-
highWaterMark?: number;
|
|
1549
|
-
asUint8Array?: boolean;
|
|
1550
|
-
}
|
|
1551
|
-
/**
|
|
1552
|
-
* Async generator function type for streaming
|
|
1553
|
-
*/
|
|
1554
|
-
export type StreamGenerator<T = unknown> = () => AsyncGenerator<T, void, unknown>;
|
|
1555
|
-
/**
|
|
1556
|
-
* Direct stream handler function type
|
|
1557
|
-
*/
|
|
1558
|
-
export type DirectStreamHandler = (_writer: DirectStreamWriter) => Promise<void>;
|
|
1559
|
-
/**
|
|
1560
|
-
* Buffered stream handler function type
|
|
1561
|
-
*/
|
|
1562
|
-
export type BufferedStreamHandler = (_writer: BufferedStreamWriter) => Promise<void>;
|
|
1563
|
-
/**
|
|
1564
|
-
* Transform function type for stream transformation
|
|
1565
|
-
*/
|
|
1566
|
-
export type TransformFunction<T = Uint8Array, R = string | Uint8Array> = (_chunk: T) => R | Promise<R>;
|
|
1567
|
-
/**
|
|
1568
|
-
* Advanced Error Handling Types
|
|
1569
|
-
*/
|
|
1570
|
-
export interface ErrorContext {
|
|
1571
|
-
requestId?: string;
|
|
1572
|
-
userId?: string | number;
|
|
1573
|
-
traceId?: string;
|
|
1574
|
-
spanId?: string;
|
|
1575
|
-
route?: string;
|
|
1576
|
-
method?: string;
|
|
1577
|
-
url?: string;
|
|
1578
|
-
userAgent?: string;
|
|
1579
|
-
ip?: string;
|
|
1580
|
-
timestamp?: Date;
|
|
1581
|
-
metadata?: ErrorMetadata;
|
|
1582
|
-
}
|
|
1583
|
-
export interface ErrorReportingConfig {
|
|
1584
|
-
enabled: boolean;
|
|
1585
|
-
service: 'sentry' | 'bugsnag' | 'custom';
|
|
1586
|
-
dsn?: string;
|
|
1587
|
-
apiKey?: string;
|
|
1588
|
-
environment?: string;
|
|
1589
|
-
release?: string;
|
|
1590
|
-
sampleRate?: number;
|
|
1591
|
-
beforeSend?: (error: Error, context: ErrorContext) => Error | null;
|
|
1592
|
-
filters?: {
|
|
1593
|
-
ignoreErrors?: (string | RegExp)[];
|
|
1594
|
-
ignoreCodes?: string[];
|
|
1595
|
-
ignoreUrls?: (string | RegExp)[];
|
|
1596
|
-
allowUrls?: (string | RegExp)[];
|
|
1597
|
-
};
|
|
1598
|
-
tags?: Record<string, string>;
|
|
1599
|
-
user?: {
|
|
1600
|
-
id?: string;
|
|
1601
|
-
email?: string;
|
|
1602
|
-
username?: string;
|
|
1603
|
-
};
|
|
1604
|
-
extra?: Record<string, unknown>;
|
|
1605
|
-
breadcrumbs?: {
|
|
1606
|
-
enabled: boolean;
|
|
1607
|
-
maxBreadcrumbs: number;
|
|
1608
|
-
};
|
|
1609
|
-
performance?: {
|
|
1610
|
-
enabled: boolean;
|
|
1611
|
-
tracesSampleRate: number;
|
|
1612
|
-
};
|
|
1613
|
-
}
|
|
1614
|
-
export interface CircuitBreakerConfig {
|
|
1615
|
-
name: string;
|
|
1616
|
-
failureThreshold: number;
|
|
1617
|
-
recoveryTimeout: number;
|
|
1618
|
-
timeout: number;
|
|
1619
|
-
monitoringPeriod: number;
|
|
1620
|
-
minimumRequests: number;
|
|
1621
|
-
errorThresholdPercentage: number;
|
|
1622
|
-
halfOpenMaxCalls: number;
|
|
1623
|
-
resetTimeout: number;
|
|
1624
|
-
onStateChange?: (state: 'CLOSED' | 'OPEN' | 'HALF_OPEN', name: string) => void;
|
|
1625
|
-
onFailure?: (error: Error, name: string) => void;
|
|
1626
|
-
onSuccess?: (name: string) => void;
|
|
1627
|
-
shouldTripOnError?: (error: Error) => boolean;
|
|
1628
|
-
}
|
|
1629
|
-
export interface DegradationConfig {
|
|
1630
|
-
enabled: boolean;
|
|
1631
|
-
fallbackStrategies: {
|
|
1632
|
-
[serviceName: string]: {
|
|
1633
|
-
type: 'cache' | 'static' | 'simplified' | 'redirect' | 'custom';
|
|
1634
|
-
priority: number;
|
|
1635
|
-
timeout: number;
|
|
1636
|
-
retries: number;
|
|
1637
|
-
backoff: {
|
|
1638
|
-
type: 'fixed' | 'exponential';
|
|
1639
|
-
delay: number;
|
|
1640
|
-
maxDelay?: number;
|
|
1641
|
-
};
|
|
1642
|
-
fallbackHandler?: (error: FallbackError, context: ErrorContext) => Promise<Response>;
|
|
1643
|
-
cacheConfig?: {
|
|
1644
|
-
key: string;
|
|
1645
|
-
ttl: number;
|
|
1646
|
-
staleWhileRevalidate: boolean;
|
|
1647
|
-
};
|
|
1648
|
-
staticResponse?: {
|
|
1649
|
-
status: number;
|
|
1650
|
-
body: StaticResponseBody;
|
|
1651
|
-
headers?: Record<string, string>;
|
|
1652
|
-
};
|
|
1653
|
-
redirectConfig?: {
|
|
1654
|
-
url: string;
|
|
1655
|
-
permanent: boolean;
|
|
1656
|
-
};
|
|
1657
|
-
};
|
|
1658
|
-
};
|
|
1659
|
-
healthChecks: {
|
|
1660
|
-
[serviceName: string]: {
|
|
1661
|
-
enabled: boolean;
|
|
1662
|
-
endpoint: string;
|
|
1663
|
-
interval: number;
|
|
1664
|
-
timeout: number;
|
|
1665
|
-
retries: number;
|
|
1666
|
-
expectedStatus: number[];
|
|
1667
|
-
expectedBody?: string | RegExp;
|
|
1668
|
-
headers?: Record<string, string>;
|
|
1669
|
-
onHealthy?: () => void;
|
|
1670
|
-
onUnhealthy?: (error: Error) => void;
|
|
1671
|
-
};
|
|
1672
|
-
};
|
|
1673
|
-
monitoring: {
|
|
1674
|
-
enabled: boolean;
|
|
1675
|
-
alertThresholds: {
|
|
1676
|
-
errorRate: number;
|
|
1677
|
-
responseTime: number;
|
|
1678
|
-
availability: number;
|
|
1679
|
-
};
|
|
1680
|
-
};
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* Request/Response Enhancement Types
|
|
1684
|
-
*/
|
|
1685
|
-
export interface RequestMacroMethods {
|
|
1686
|
-
wantsJson: () => boolean;
|
|
1687
|
-
wantsHtml: () => boolean;
|
|
1688
|
-
wantsXml: () => boolean;
|
|
1689
|
-
expectsJson: () => boolean;
|
|
1690
|
-
isAjax: () => boolean;
|
|
1691
|
-
isPjax: () => boolean;
|
|
1692
|
-
isMobile: () => boolean;
|
|
1693
|
-
isBot: () => boolean;
|
|
1694
|
-
isSecure: () => boolean;
|
|
1695
|
-
ip: () => string;
|
|
1696
|
-
ips: () => string[];
|
|
1697
|
-
userAgent: () => string;
|
|
1698
|
-
referer: () => string | null;
|
|
1699
|
-
bearerToken: () => string | null;
|
|
1700
|
-
basicAuth: () => {
|
|
1701
|
-
username: string;
|
|
1702
|
-
password: string;
|
|
1703
|
-
} | null;
|
|
1704
|
-
hasHeader: (name: string) => boolean;
|
|
1705
|
-
header: (name: string, defaultValue?: string) => string | null;
|
|
1706
|
-
allHeaders: () => Record<string, string>;
|
|
1707
|
-
input: <T = InputValue>(key: string, defaultValue?: T) => T;
|
|
1708
|
-
all: () => RequestInput;
|
|
1709
|
-
only: (keys: string[]) => RequestInput;
|
|
1710
|
-
except: (keys: string[]) => RequestInput;
|
|
1711
|
-
has: (key: string) => boolean;
|
|
1712
|
-
hasAny: (keys: string[]) => boolean;
|
|
1713
|
-
missing: (key: string) => boolean;
|
|
1714
|
-
filled: (key: string) => boolean;
|
|
1715
|
-
getQuery: <T = InputValue>(key?: string, defaultValue?: T) => T;
|
|
1716
|
-
param: <T = InputValue>(key: string, defaultValue?: T) => T;
|
|
1717
|
-
cookie: (name: string, defaultValue?: string) => string | null;
|
|
1718
|
-
cookies: () => Record<string, string>;
|
|
1719
|
-
file: (name: string) => FileInfo | null;
|
|
1720
|
-
hasFile: (name: string) => boolean;
|
|
1721
|
-
path: () => string;
|
|
1722
|
-
fullUrl: () => string;
|
|
1723
|
-
root: () => string;
|
|
1724
|
-
is: (pattern: string) => boolean;
|
|
1725
|
-
route: () => string | null;
|
|
1726
|
-
fingerprint: () => string;
|
|
1727
|
-
signature: (secret: string) => string;
|
|
1728
|
-
merge: (data: RequestInput) => void;
|
|
1729
|
-
replace: (data: RequestInput) => void;
|
|
1730
|
-
age: () => number;
|
|
1731
|
-
isFromTrustedProxy: (trustedProxies?: string[]) => boolean;
|
|
1732
|
-
contentLength: () => number;
|
|
1733
|
-
contentType: () => string | null;
|
|
1734
|
-
isContentType: (type: string) => boolean;
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* Enhanced streaming generator types with extreme narrowing
|
|
1738
|
-
*/
|
|
1739
|
-
export type StreamGeneratorSync<T = string | Uint8Array> = () => Generator<T, void, unknown>;
|
|
1740
|
-
export type AsyncStreamGenerator<T = string | Uint8Array> = () => AsyncGenerator<T, void, unknown>;
|
|
1741
|
-
export type StreamCallbackGenerator<T = string | Uint8Array> = StreamGenerator<T> | AsyncStreamGenerator<T>;
|
|
1742
|
-
/**
|
|
1743
|
-
* SSE Event generator with strict typing
|
|
1744
|
-
*/
|
|
1745
|
-
export type SSEEventGenerator<T = unknown> = () => Generator<SSEEvent<T>, void, unknown> | AsyncGenerator<SSEEvent<T>, void, unknown>;
|
|
1746
|
-
/**
|
|
1747
|
-
* Extreme narrow types for Laravel-style methods with template literal patterns
|
|
1748
|
-
*/
|
|
1749
|
-
export interface EnhancedLaravelStreamingMethods {
|
|
1750
|
-
/**
|
|
1751
|
-
* Laravel-style response()->stream() with extreme type narrowing
|
|
1752
|
-
*/
|
|
1753
|
-
stream: <T extends string | Uint8Array = string>(callback: StreamCallbackGenerator<T>, status?: ResponseStatus, headers?: Record<string, string>) => Response;
|
|
1754
|
-
/**
|
|
1755
|
-
* Laravel-style response()->streamJson() with strict object key typing
|
|
1756
|
-
*/
|
|
1757
|
-
streamJson: <T, K extends string = string>(data: Record<K, Iterable<T> | AsyncIterable<T>>, status?: ResponseStatus, headers?: Record<string, string>) => Response;
|
|
1758
|
-
/**
|
|
1759
|
-
* Laravel-style response()->eventStream() with strict SSE typing
|
|
1760
|
-
*/
|
|
1761
|
-
eventStream: <T = unknown>(callback: SSEEventGenerator<T>, headers?: Record<string, string>) => Response;
|
|
1762
|
-
/**
|
|
1763
|
-
* Laravel-style response()->streamDownload() with filename validation
|
|
1764
|
-
*/
|
|
1765
|
-
streamDownload: <T extends string | Uint8Array = string>(callback: StreamCallbackGenerator<T>, filename: `${string}.${string}`, // Must have extension
|
|
1766
|
-
headers?: Record<string, string>) => Response;
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* Enhanced model binding with strict key typing
|
|
1770
|
-
*/
|
|
1771
|
-
export interface EnhancedLaravelModelBindingMethods {
|
|
1772
|
-
/**
|
|
1773
|
-
* Laravel-style Route::model() with key validation
|
|
1774
|
-
*/
|
|
1775
|
-
model: <T, K extends string>(key: K, modelClass: string | ((_value: string) => Promise<T | null>), callback?: (model: T | null) => Response | null) => Router & {
|
|
1776
|
-
[P in K]: T;
|
|
1777
|
-
};
|
|
1778
|
-
/**
|
|
1779
|
-
* Scoped bindings with relationship validation
|
|
1780
|
-
*/
|
|
1781
|
-
scopedBindings: <Parent extends string, Child extends string>(bindings: Record<Child, Parent>) => MiddlewareHandler;
|
|
1782
|
-
}
|