@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/router/index.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { ActionHandler, Route } from '../types';
|
|
2
|
-
import { Dependencies, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, SkipConditions } from '../middleware/pipeline';
|
|
3
|
-
import { FluentRouteBuilder, FluentRouter, RouteFactory, router, RouterUtils } from './fluent-routing';
|
|
4
|
-
import { Router } from './router';
|
|
5
|
-
import '../types';
|
|
6
|
-
export { Router };
|
|
7
|
-
export { applyRequestEnhancements } from './router';
|
|
8
|
-
declare module './router' {
|
|
9
|
-
interface Router {
|
|
10
|
-
stream: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, status?: number, headers?: Record<string, string>) => Response;
|
|
11
|
-
streamJson: <T>(data: Record<string, Iterable<T> | AsyncIterable<T>>, status?: number, headers?: Record<string, string>) => Response;
|
|
12
|
-
eventStream: <_T = any>(callback: () => Generator<{
|
|
13
|
-
data: any;
|
|
14
|
-
event?: string;
|
|
15
|
-
id?: string;
|
|
16
|
-
retry?: number;
|
|
17
|
-
}, void, unknown> | AsyncGenerator<{
|
|
18
|
-
data: any;
|
|
19
|
-
event?: string;
|
|
20
|
-
id?: string;
|
|
21
|
-
retry?: number;
|
|
22
|
-
}, void, unknown>, headers?: Record<string, string>) => Response;
|
|
23
|
-
streamDownload: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, filename: string, headers?: Record<string, string>) => Response;
|
|
24
|
-
streamFile: (filePath: string, request: any, options?: {
|
|
25
|
-
contentType?: string;
|
|
26
|
-
enableRanges?: boolean;
|
|
27
|
-
chunkSize?: number;
|
|
28
|
-
}) => Promise<Response>;
|
|
29
|
-
streamFileWithRanges: (filePath: string, req: any) => Promise<Response>;
|
|
30
|
-
streamResponse: (generator: () => AsyncGenerator<string | Uint8Array, void, unknown>, options?: {
|
|
31
|
-
headers?: Record<string, string>;
|
|
32
|
-
status?: number;
|
|
33
|
-
}) => Response;
|
|
34
|
-
transformStream: (transformer: (chunk: string | Uint8Array) => string | Uint8Array | Promise<string | Uint8Array>, options?: {
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
status?: number;
|
|
37
|
-
}) => (req: Request) => Response;
|
|
38
|
-
model: <T>(key: string, modelClass: string | ((_value: string) => Promise<T | null>), callback?: (model: T | null) => Response | null) => Router;
|
|
39
|
-
implicitBinding: () => any;
|
|
40
|
-
missing: (callback: (req: any) => Response) => any;
|
|
41
|
-
scopedBindings: (bindings: Record<string, string>) => any;
|
|
42
|
-
clearModelCache: (modelName?: string) => Router;
|
|
43
|
-
getModelStats: () => {
|
|
44
|
-
totalEntries: number;
|
|
45
|
-
validEntries: number;
|
|
46
|
-
expiredEntries: number;
|
|
47
|
-
models: number;
|
|
48
|
-
};
|
|
49
|
-
readonly modelRegistry: {
|
|
50
|
-
has: (name: string) => boolean;
|
|
51
|
-
register: <_T>(name: string, config: any) => void;
|
|
52
|
-
resolve: <_T>(modelName: string, params: Record<string, string>, req?: any) => Promise<any>;
|
|
53
|
-
createErrorResponse: (modelName: string, result: any, params: Record<string, string>) => Response;
|
|
54
|
-
clearCache: (modelName: string, params?: Record<string, string>) => void;
|
|
55
|
-
clearAllCache: () => void;
|
|
56
|
-
getCacheStats: () => any;
|
|
57
|
-
};
|
|
58
|
-
matchRoute: (path: string, method: string, domain?: string) => {
|
|
59
|
-
route: Route;
|
|
60
|
-
params: Record<string, string>;
|
|
61
|
-
} | undefined;
|
|
62
|
-
getAllowedMethods: (path: string, domain?: string) => string[];
|
|
63
|
-
clearRouteCache: () => void;
|
|
64
|
-
getCacheStats: () => any;
|
|
65
|
-
getRouteStats: () => any;
|
|
66
|
-
warmRouteCache: (commonPaths: Array<{
|
|
67
|
-
path: string;
|
|
68
|
-
method: string;
|
|
69
|
-
}>) => void;
|
|
70
|
-
getRoutesByMethod: () => any;
|
|
71
|
-
getRouteConflicts: () => any;
|
|
72
|
-
rebuildRouteCompiler: () => void;
|
|
73
|
-
optimizeRoutes: (usageStats?: Record<string, number>) => void;
|
|
74
|
-
addRouteToCompiler: (route: Route) => void;
|
|
75
|
-
initializeRouteCompiler: () => void;
|
|
76
|
-
health: () => Router;
|
|
77
|
-
renderView: (view: string, data?: Record<string, any>, options?: {
|
|
78
|
-
layout?: string;
|
|
79
|
-
}) => Promise<string>;
|
|
80
|
-
view: (path: string, view: string, data?: Record<string, any>, options?: {
|
|
81
|
-
layout?: string;
|
|
82
|
-
status?: number;
|
|
83
|
-
headers?: Record<string, string>;
|
|
84
|
-
}) => Router;
|
|
85
|
-
where: ((_param: string, _pattern: string | RegExp) => Router) & ((constraints: Record<string, string | RegExp>) => Router);
|
|
86
|
-
whereNumber: (param: string) => Router;
|
|
87
|
-
whereAlpha: (param: string) => Router;
|
|
88
|
-
whereAlphaNumeric: (param: string) => Router;
|
|
89
|
-
whereUuid: (param: string) => Router;
|
|
90
|
-
whereIn: (param: string, values: string[]) => Router;
|
|
91
|
-
domain: (domain: string, callback: () => void) => Router;
|
|
92
|
-
resource: (name: string, handlers: {
|
|
93
|
-
index?: ActionHandler;
|
|
94
|
-
show?: ActionHandler;
|
|
95
|
-
store?: ActionHandler;
|
|
96
|
-
update?: ActionHandler;
|
|
97
|
-
destroy?: ActionHandler;
|
|
98
|
-
create?: ActionHandler;
|
|
99
|
-
edit?: ActionHandler;
|
|
100
|
-
}) => Router;
|
|
101
|
-
onError: (handler: (error: Error) => Response | Promise<Response>) => Router;
|
|
102
|
-
redirect: (url: string, status?: 301 | 302 | 303 | 307 | 308) => Response;
|
|
103
|
-
permanentRedirect: (url: string) => Response;
|
|
104
|
-
fallback: (handler: ActionHandler) => Router;
|
|
105
|
-
route: (name: string, params?: Record<string, string>) => string;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export { Dependencies, FluentRouteBuilder, FluentRouter, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, RouteFactory, router, RouterUtils, SkipConditions };
|
|
109
|
-
export * from '../routing/route-caching';
|
|
110
|
-
export * from '../routing/route-throttling';
|
|
111
|
-
export * from '../routing/subdomain-routing';
|
|
112
|
-
export { createHandlerResolver, resolveHandler, wrapResponse } from './handler-resolver';
|
|
113
|
-
export * from './validation-integration';
|
|
114
|
-
export type { DiscoveredRoute, FileBasedRoutingConfig } from './file-based-routing';
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { MiddlewareHandler } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Middleware Group Registry
|
|
4
|
-
*
|
|
5
|
-
* Allows defining named groups of middleware that can be applied to routes.
|
|
6
|
-
* Similar to Laravel's middleware groups (web, api).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // Define groups
|
|
10
|
-
* groups.define('web', ['session', 'csrf', 'cors'])
|
|
11
|
-
* groups.define('api', ['throttle:60,1', 'cors'])
|
|
12
|
-
*
|
|
13
|
-
* // Use on routes
|
|
14
|
-
* router.group({ middleware: 'web' }, () => { ... })
|
|
15
|
-
*/
|
|
16
|
-
export declare class MiddlewareGroupRegistry {
|
|
17
|
-
private groups;
|
|
18
|
-
private globalMiddleware;
|
|
19
|
-
private middlewarePriority;
|
|
20
|
-
/**
|
|
21
|
-
* Define a middleware group
|
|
22
|
-
*/
|
|
23
|
-
define(name: string, middleware: (string | MiddlewareHandler)[]): this;
|
|
24
|
-
/**
|
|
25
|
-
* Extend an existing group with additional middleware
|
|
26
|
-
*/
|
|
27
|
-
extend(name: string, middleware: (string | MiddlewareHandler)[]): this;
|
|
28
|
-
/**
|
|
29
|
-
* Prepend middleware to an existing group
|
|
30
|
-
*/
|
|
31
|
-
prepend(name: string, middleware: (string | MiddlewareHandler)[]): this;
|
|
32
|
-
/**
|
|
33
|
-
* Get middleware for a group
|
|
34
|
-
*/
|
|
35
|
-
get(name: string): (string | MiddlewareHandler)[];
|
|
36
|
-
/**
|
|
37
|
-
* Check if a group exists
|
|
38
|
-
*/
|
|
39
|
-
has(name: string): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Remove a group
|
|
42
|
-
*/
|
|
43
|
-
remove(name: string): this;
|
|
44
|
-
/**
|
|
45
|
-
* Resolve a middleware reference, expanding group names into their middleware
|
|
46
|
-
*/
|
|
47
|
-
resolve(middleware: string | MiddlewareHandler): (string | MiddlewareHandler)[];
|
|
48
|
-
/**
|
|
49
|
-
* Resolve multiple middleware references, expanding groups
|
|
50
|
-
*/
|
|
51
|
-
resolveAll(middleware: (string | MiddlewareHandler)[]): (string | MiddlewareHandler)[];
|
|
52
|
-
/**
|
|
53
|
-
* Add middleware to the global stack (runs on every request)
|
|
54
|
-
*/
|
|
55
|
-
pushGlobal(...middleware: (string | MiddlewareHandler)[]): this;
|
|
56
|
-
/**
|
|
57
|
-
* Prepend middleware to the global stack
|
|
58
|
-
*/
|
|
59
|
-
prependGlobal(...middleware: (string | MiddlewareHandler)[]): this;
|
|
60
|
-
/**
|
|
61
|
-
* Remove middleware from the global stack
|
|
62
|
-
*/
|
|
63
|
-
removeGlobal(middleware: string): this;
|
|
64
|
-
/**
|
|
65
|
-
* Get the global middleware stack
|
|
66
|
-
*/
|
|
67
|
-
getGlobal(): (string | MiddlewareHandler)[];
|
|
68
|
-
/**
|
|
69
|
-
* Set execution priority for a middleware (lower = runs first)
|
|
70
|
-
*/
|
|
71
|
-
setPriority(name: string, priority: number): this;
|
|
72
|
-
/**
|
|
73
|
-
* Sort middleware by priority
|
|
74
|
-
*/
|
|
75
|
-
sortByPriority(middleware: (string | MiddlewareHandler)[]): (string | MiddlewareHandler)[];
|
|
76
|
-
/**
|
|
77
|
-
* Filter middleware by applying except/only rules.
|
|
78
|
-
*
|
|
79
|
-
* @param middleware - Full middleware list
|
|
80
|
-
* @param options - except or only filter
|
|
81
|
-
*/
|
|
82
|
-
filter(middleware: (string | MiddlewareHandler)[], options: {
|
|
83
|
-
except?: string[];
|
|
84
|
-
only?: string[];
|
|
85
|
-
}): (string | MiddlewareHandler)[];
|
|
86
|
-
/**
|
|
87
|
-
* Clear all groups and global middleware
|
|
88
|
-
*/
|
|
89
|
-
flush(): void;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Default middleware group registry instance
|
|
93
|
-
*/
|
|
94
|
-
export declare const middlewareGroups: MiddlewareGroupRegistry;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, MiddlewareHandler } from '../types';
|
|
2
|
-
import type { Router } from './router';
|
|
3
|
-
export type SkipConditionFn = (_req: EnhancedRequest) => boolean;
|
|
4
|
-
export type SkipConditionsList = SkipConditionFn[];
|
|
5
|
-
/**
|
|
6
|
-
* Skip condition helpers
|
|
7
|
-
*/
|
|
8
|
-
export declare const SkipConditions: {
|
|
9
|
-
skipForPaths: (paths: string[]) => SkipConditionFn;
|
|
10
|
-
skipForMethods: (methods: string[]) => SkipConditionFn;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Dependency helpers
|
|
14
|
-
*/
|
|
15
|
-
export declare const Dependencies: {
|
|
16
|
-
cache: (config: {
|
|
17
|
-
type: string;
|
|
18
|
-
ttl: number;
|
|
19
|
-
}) => {
|
|
20
|
-
type: string;
|
|
21
|
-
config: {
|
|
22
|
-
type: string;
|
|
23
|
-
ttl: number;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
logger: (level: string) => {
|
|
27
|
-
type: string;
|
|
28
|
-
config: {
|
|
29
|
-
level: string;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
declare class MiddlewarePipeline {
|
|
34
|
-
registerDependency(_key: string, _dependency: any): this;
|
|
35
|
-
registerSkipConditions(_middleware: MiddlewareHandler, _conditions: SkipConditionsList): void;
|
|
36
|
-
getStats(): any;
|
|
37
|
-
getCacheInfo(): any;
|
|
38
|
-
clearCache(): this;
|
|
39
|
-
compilePipeline(_key: string, _middleware: MiddlewareHandler[], _options?: any): void;
|
|
40
|
-
execute(_key: string, _req: EnhancedRequest, _handler: () => Promise<Response>): Promise<Response>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Integration layer for middleware pipeline with the router
|
|
44
|
-
*/
|
|
45
|
-
export declare function registerMiddlewarePipeline(RouterClass: typeof Router): void;
|
|
46
|
-
/**
|
|
47
|
-
* Middleware factory for common use cases
|
|
48
|
-
*/
|
|
49
|
-
export declare class MiddlewareFactory {
|
|
50
|
-
private pipeline;
|
|
51
|
-
constructor(pipeline: MiddlewarePipeline);
|
|
52
|
-
/**
|
|
53
|
-
* Create authentication middleware with conditional execution
|
|
54
|
-
*/
|
|
55
|
-
createAuthMiddleware(options?: {
|
|
56
|
-
skipPaths?: string[];
|
|
57
|
-
skipMethods?: string[];
|
|
58
|
-
requireRoles?: string[];
|
|
59
|
-
jwtSecret?: string;
|
|
60
|
-
}): MiddlewareHandler;
|
|
61
|
-
/**
|
|
62
|
-
* Create rate limiting middleware with dependency injection
|
|
63
|
-
*/
|
|
64
|
-
createRateLimitMiddleware(options: {
|
|
65
|
-
maxRequests: number;
|
|
66
|
-
windowMs: number;
|
|
67
|
-
skipPaths?: string[];
|
|
68
|
-
}): MiddlewareHandler;
|
|
69
|
-
/**
|
|
70
|
-
* Create logging middleware with dependency injection
|
|
71
|
-
*/
|
|
72
|
-
createLoggingMiddleware(options?: {
|
|
73
|
-
level?: string;
|
|
74
|
-
skipPaths?: string[];
|
|
75
|
-
includeBody?: boolean;
|
|
76
|
-
}): MiddlewareHandler;
|
|
77
|
-
/**
|
|
78
|
-
* Create CORS middleware with conditional execution
|
|
79
|
-
*/
|
|
80
|
-
createCorsMiddleware(options?: {
|
|
81
|
-
origin?: string | string[];
|
|
82
|
-
methods?: string[];
|
|
83
|
-
allowedHeaders?: string[];
|
|
84
|
-
credentials?: boolean;
|
|
85
|
-
}): MiddlewareHandler;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Helper function to setup common middleware stack
|
|
89
|
-
*/
|
|
90
|
-
export declare function setupMiddlewareStack(router: any, options?: {
|
|
91
|
-
auth?: {
|
|
92
|
-
jwtSecret: string;
|
|
93
|
-
skipPaths?: string[];
|
|
94
|
-
requireRoles?: string[];
|
|
95
|
-
};
|
|
96
|
-
rateLimit?: {
|
|
97
|
-
maxRequests: number;
|
|
98
|
-
windowMs: number;
|
|
99
|
-
skipPaths?: string[];
|
|
100
|
-
};
|
|
101
|
-
cors?: {
|
|
102
|
-
origin?: string | string[];
|
|
103
|
-
methods?: string[];
|
|
104
|
-
allowedHeaders?: string[];
|
|
105
|
-
credentials?: boolean;
|
|
106
|
-
};
|
|
107
|
-
logging?: {
|
|
108
|
-
level?: string;
|
|
109
|
-
skipPaths?: string[];
|
|
110
|
-
};
|
|
111
|
-
}): MiddlewareHandler[];
|
|
112
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Router } from './router';
|
|
2
|
-
/**
|
|
3
|
-
* Optimized route matching extension for Router class
|
|
4
|
-
* Replaces the original route matching with high-performance trie-based matching
|
|
5
|
-
*/
|
|
6
|
-
export declare function registerOptimizedRouteMatching(RouterClass: typeof Router): void;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type { HTTPMethod, MatchResult, Route } from '../types';
|
|
2
|
-
import type { CompiledRoute } from './route-trie';
|
|
3
|
-
/**
|
|
4
|
-
* Route compilation options
|
|
5
|
-
*/
|
|
6
|
-
export interface RouteCompilerOptions {
|
|
7
|
-
enableCaching: boolean;
|
|
8
|
-
enableMethodGrouping: boolean;
|
|
9
|
-
enablePriorityOptimization: boolean;
|
|
10
|
-
cacheSize: number;
|
|
11
|
-
precompilePatterns: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Route matching statistics for performance monitoring
|
|
15
|
-
*/
|
|
16
|
-
export interface RouteMatchStats {
|
|
17
|
-
totalMatches: number;
|
|
18
|
-
cacheHits: number;
|
|
19
|
-
cacheMisses: number;
|
|
20
|
-
averageMatchTime: number;
|
|
21
|
-
trieDepth: number;
|
|
22
|
-
methodDistribution: Record<string, number>;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* High-performance route compiler with pre-compilation and optimization
|
|
26
|
-
*/
|
|
27
|
-
export declare class RouteCompiler {
|
|
28
|
-
private trie;
|
|
29
|
-
private matchCache;
|
|
30
|
-
private cacheKeys;
|
|
31
|
-
private stats;
|
|
32
|
-
private options;
|
|
33
|
-
constructor(options?: Partial<RouteCompilerOptions>);
|
|
34
|
-
/**
|
|
35
|
-
* Add a route to the compiler
|
|
36
|
-
* @returns true if route was added, false if it's a duplicate
|
|
37
|
-
*/
|
|
38
|
-
addRoute(route: Route): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Check if a route is an exact duplicate of an existing route
|
|
41
|
-
*/
|
|
42
|
-
private checkForDuplicateRoute;
|
|
43
|
-
/**
|
|
44
|
-
* Pre-compile route patterns for faster matching
|
|
45
|
-
*/
|
|
46
|
-
private patternCache;
|
|
47
|
-
/**
|
|
48
|
-
* Extract parameter names from a route path
|
|
49
|
-
*/
|
|
50
|
-
private extractParamNames;
|
|
51
|
-
/**
|
|
52
|
-
* Pre-compile route patterns for faster matching
|
|
53
|
-
*/
|
|
54
|
-
private precompileRoutePattern;
|
|
55
|
-
/**
|
|
56
|
-
* Convert Laravel-style route to a simple regex pattern
|
|
57
|
-
* @param path The route path with Laravel-style parameters
|
|
58
|
-
* @param constraints Optional constraints for route parameters
|
|
59
|
-
*/
|
|
60
|
-
private convertToURLPattern;
|
|
61
|
-
/**
|
|
62
|
-
* Match a request path and method to a route
|
|
63
|
-
*/
|
|
64
|
-
match(path: string, method: HTTPMethod): MatchResult | null;
|
|
65
|
-
/**
|
|
66
|
-
* Add an entry to the cache with LRU eviction if needed
|
|
67
|
-
*/
|
|
68
|
-
private addToCache;
|
|
69
|
-
/**
|
|
70
|
-
* Update LRU tracking for a cache key
|
|
71
|
-
*/
|
|
72
|
-
private updateCacheLRU;
|
|
73
|
-
/**
|
|
74
|
-
* Update average match time statistics
|
|
75
|
-
*/
|
|
76
|
-
private updateMatchTime;
|
|
77
|
-
/**
|
|
78
|
-
* Get all compiled routes sorted by priority
|
|
79
|
-
*/
|
|
80
|
-
getCompiledRoutes(): CompiledRoute[];
|
|
81
|
-
/**
|
|
82
|
-
* Get routes grouped by HTTP method
|
|
83
|
-
*/
|
|
84
|
-
getRoutesByMethod(): Map<HTTPMethod, CompiledRoute[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Warm up the cache with common routes
|
|
87
|
-
* @param commonPaths Array of paths and methods to pre-cache
|
|
88
|
-
* @param options Optional warming options
|
|
89
|
-
* @param options.force If true, enables caching temporarily even if disabled in compiler options
|
|
90
|
-
* @param options.precompile If true, performs a second match to ensure cache hits are recorded
|
|
91
|
-
* @returns Statistics about the warming operation
|
|
92
|
-
*/
|
|
93
|
-
warmCache(commonPaths: Array<{
|
|
94
|
-
path: string;
|
|
95
|
-
method: HTTPMethod;
|
|
96
|
-
}>, options?: {
|
|
97
|
-
force?: boolean;
|
|
98
|
-
precompile?: boolean;
|
|
99
|
-
}): {
|
|
100
|
-
warmedPaths: number;
|
|
101
|
-
cacheSize: number;
|
|
102
|
-
hitRate: number;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Clear all caches and reset statistics
|
|
106
|
-
*/
|
|
107
|
-
clear(): void;
|
|
108
|
-
/**
|
|
109
|
-
* Get performance statistics
|
|
110
|
-
*/
|
|
111
|
-
getStats(): RouteMatchStats;
|
|
112
|
-
/**
|
|
113
|
-
* Get cache statistics
|
|
114
|
-
*/
|
|
115
|
-
getCacheStats(): {
|
|
116
|
-
size: number;
|
|
117
|
-
maxSize: number;
|
|
118
|
-
hitRate: number;
|
|
119
|
-
enabled: boolean;
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Optimize route order based on usage patterns
|
|
123
|
-
*/
|
|
124
|
-
optimizeRouteOrder(_usageStats: Record<string, number>): void;
|
|
125
|
-
/**
|
|
126
|
-
* Get route conflicts (overlapping patterns)
|
|
127
|
-
*/
|
|
128
|
-
getRouteConflicts(): Array<{
|
|
129
|
-
routes: CompiledRoute[];
|
|
130
|
-
conflictType: 'overlap' | 'duplicate' | 'ambiguous';
|
|
131
|
-
severity: 'low' | 'medium' | 'high';
|
|
132
|
-
}>;
|
|
133
|
-
/**
|
|
134
|
-
* Check if two routes conflict
|
|
135
|
-
*/
|
|
136
|
-
private routesConflict;
|
|
137
|
-
/**
|
|
138
|
-
* Check if two route patterns overlap
|
|
139
|
-
*/
|
|
140
|
-
private patternsOverlap;
|
|
141
|
-
/**
|
|
142
|
-
* Get conflict severity
|
|
143
|
-
*/
|
|
144
|
-
private getConflictSeverity;
|
|
145
|
-
/**
|
|
146
|
-
* Get conflict type
|
|
147
|
-
*/
|
|
148
|
-
private getConflictType;
|
|
149
|
-
/**
|
|
150
|
-
* Check if routes have ambiguous parameters
|
|
151
|
-
*/
|
|
152
|
-
private hasAmbiguousParameters;
|
|
153
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { HTTPMethod, Route } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Route segment types for the trie
|
|
4
|
-
*/
|
|
5
|
-
export type RouteSegmentType = 'static' | 'parameter' | 'wildcard' | 'optional';
|
|
6
|
-
export interface RouteSegment {
|
|
7
|
-
type: RouteSegmentType;
|
|
8
|
-
value: string;
|
|
9
|
-
paramName?: string;
|
|
10
|
-
pattern?: RegExp;
|
|
11
|
-
optional?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface CompiledRoute {
|
|
14
|
-
route: Route;
|
|
15
|
-
segments: RouteSegment[];
|
|
16
|
-
paramNames: string[];
|
|
17
|
-
priority: number;
|
|
18
|
-
staticScore: number;
|
|
19
|
-
dynamicScore: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Trie node for efficient route matching
|
|
23
|
-
*/
|
|
24
|
-
export declare class TrieNode {
|
|
25
|
-
children: Map<string, TrieNode>;
|
|
26
|
-
paramChild: TrieNode | null;
|
|
27
|
-
wildcardChild: TrieNode | null;
|
|
28
|
-
routes: Map<HTTPMethod, CompiledRoute>;
|
|
29
|
-
paramName: string | null;
|
|
30
|
-
pattern: RegExp | null;
|
|
31
|
-
isEndpoint: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Add a route to this node
|
|
34
|
-
*/
|
|
35
|
-
addRoute(method: HTTPMethod, compiledRoute: CompiledRoute): void;
|
|
36
|
-
/**
|
|
37
|
-
* Get route for a specific HTTP method
|
|
38
|
-
*/
|
|
39
|
-
getRoute(method: HTTPMethod): CompiledRoute | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Get all routes at this node
|
|
42
|
-
*/
|
|
43
|
-
getAllRoutes(): CompiledRoute[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Route matching result with extracted parameters
|
|
47
|
-
*/
|
|
48
|
-
export interface RouteMatch {
|
|
49
|
-
route: Route;
|
|
50
|
-
params: Record<string, string>;
|
|
51
|
-
score: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* High-performance route trie for O(log n) route matching
|
|
55
|
-
*/
|
|
56
|
-
export declare class RouteTrie {
|
|
57
|
-
private root;
|
|
58
|
-
private compiledRoutes;
|
|
59
|
-
private methodTries;
|
|
60
|
-
constructor();
|
|
61
|
-
/**
|
|
62
|
-
* Compile a route pattern into segments
|
|
63
|
-
*/
|
|
64
|
-
compileRoute(route: Route): CompiledRoute;
|
|
65
|
-
/**
|
|
66
|
-
* Parse path into segments
|
|
67
|
-
*/
|
|
68
|
-
private parsePathSegments;
|
|
69
|
-
/**
|
|
70
|
-
* Calculate route priority (higher = more specific)
|
|
71
|
-
*/
|
|
72
|
-
private calculateRoutePriority;
|
|
73
|
-
/**
|
|
74
|
-
* Add a route to the trie
|
|
75
|
-
*/
|
|
76
|
-
addRoute(route: Route): void;
|
|
77
|
-
/**
|
|
78
|
-
* Insert compiled route into trie
|
|
79
|
-
*/
|
|
80
|
-
private insertRoute;
|
|
81
|
-
/**
|
|
82
|
-
* Match a path against the trie
|
|
83
|
-
*/
|
|
84
|
-
match(path: string, method: HTTPMethod): RouteMatch | null;
|
|
85
|
-
/**
|
|
86
|
-
* Recursively match path segments
|
|
87
|
-
*/
|
|
88
|
-
private matchSegments;
|
|
89
|
-
/**
|
|
90
|
-
* Get all routes for debugging
|
|
91
|
-
*/
|
|
92
|
-
getAllRoutes(): CompiledRoute[];
|
|
93
|
-
/**
|
|
94
|
-
* Remove a route from the trie
|
|
95
|
-
*/
|
|
96
|
-
removeRoute(route: Route): void;
|
|
97
|
-
/**
|
|
98
|
-
* Clear the trie
|
|
99
|
-
*/
|
|
100
|
-
clear(): void;
|
|
101
|
-
/**
|
|
102
|
-
* Get trie statistics for debugging
|
|
103
|
-
*/
|
|
104
|
-
getStats(): {
|
|
105
|
-
totalRoutes: number;
|
|
106
|
-
totalNodes: number;
|
|
107
|
-
averageDepth: number;
|
|
108
|
-
methodDistribution: Record<string, number>;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Count total nodes in trie
|
|
112
|
-
*/
|
|
113
|
-
private countNodes;
|
|
114
|
-
}
|