@stacksjs/bun-router 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/auth.d.ts +22 -8
  2. package/dist/chunk-1ahs68ys.js +18 -0
  3. package/dist/{chunk-0145g1me.js → chunk-cgptvjdf.js} +147 -75
  4. package/dist/chunk-g3ybefhg.js +1923 -0
  5. package/dist/cli.js +3 -2
  6. package/dist/container/container.d.ts +1 -0
  7. package/dist/container/contextual-binding.d.ts +0 -1
  8. package/dist/container/decorators.d.ts +2 -5
  9. package/dist/container/index.d.ts +16 -0
  10. package/dist/container/index.js +322 -0
  11. package/dist/container/service-provider.d.ts +3 -3
  12. package/dist/development/performance-profiler.d.ts +3 -3
  13. package/dist/development/route-debugger.d.ts +1 -1
  14. package/dist/development/route-inspector.d.ts +2 -2
  15. package/dist/file-serving/static-files.d.ts +16 -0
  16. package/dist/index.d.ts +17 -1
  17. package/dist/index.js +1159 -1380
  18. package/dist/middleware/cors.d.ts +9 -0
  19. package/dist/middleware/csrf.d.ts +7 -0
  20. package/dist/middleware/ddos_protection.d.ts +16 -1
  21. package/dist/middleware/rate_limit.d.ts +7 -1
  22. package/dist/middleware/request_tracer.d.ts +15 -9
  23. package/dist/middleware/response_cache.d.ts +2 -1
  24. package/dist/observability/integration.d.ts +1 -1
  25. package/dist/request/context.d.ts +12 -1
  26. package/dist/request/macros.d.ts +40 -2
  27. package/dist/response/macros.d.ts +4 -4
  28. package/dist/router/fluent-routing.d.ts +50 -13
  29. package/dist/router/handler-resolver.d.ts +8 -0
  30. package/dist/router/index.d.ts +9 -7
  31. package/dist/router/route-compiler.d.ts +8 -10
  32. package/dist/router/route-trie.d.ts +7 -1
  33. package/dist/router/router.d.ts +13 -34
  34. package/dist/router/validation-integration.d.ts +10 -4
  35. package/dist/testing/performance-testing.d.ts +2 -2
  36. package/dist/testing/test-client.d.ts +1 -1
  37. package/dist/testing/websocket-testing.d.ts +1 -1
  38. package/dist/types/middleware-types.d.ts +1 -1
  39. package/dist/types/route-inference.d.ts +9 -2
  40. package/dist/types.d.ts +62 -9
  41. package/dist/utils.d.ts +1 -1
  42. package/package.json +12 -3
  43. package/dist/router/fluent-router.d.ts +0 -315
  44. package/src/auth.ts +0 -469
  45. package/src/cache/lru-cache.ts +0 -457
  46. package/src/cache/middleware-memoization.ts +0 -531
  47. package/src/cache/route-cache-warmer.ts +0 -486
  48. package/src/cache/sqlite-cache.ts +0 -783
  49. package/src/cache/streaming-cache.ts +0 -572
  50. package/src/cli/colors.ts +0 -29
  51. package/src/cli/index.ts +0 -287
  52. package/src/cli/middleware.ts +0 -291
  53. package/src/cli/openapi.ts +0 -407
  54. package/src/cli/router.ts +0 -188
  55. package/src/cli/routes.ts +0 -265
  56. package/src/cli/utils.ts +0 -531
  57. package/src/cli.ts +0 -5
  58. package/src/config.ts +0 -322
  59. package/src/container/container.ts +0 -740
  60. package/src/container/contextual-binding.ts +0 -603
  61. package/src/container/decorators.ts +0 -359
  62. package/src/container/service-provider.ts +0 -596
  63. package/src/development/hot-reload.ts +0 -673
  64. package/src/development/index.ts +0 -499
  65. package/src/development/performance-profiler.ts +0 -717
  66. package/src/development/route-debugger.ts +0 -527
  67. package/src/development/route-inspector.ts +0 -749
  68. package/src/development/typescript-utilities.ts +0 -682
  69. package/src/docs.ts +0 -397
  70. package/src/errors/circuit-breaker.ts +0 -732
  71. package/src/errors/error-handler.ts +0 -569
  72. package/src/errors/error-reporting.ts +0 -672
  73. package/src/errors/exceptions.ts +0 -536
  74. package/src/errors/graceful-degradation.ts +0 -621
  75. package/src/errors/index.ts +0 -21
  76. package/src/errors/router-errors.ts +0 -632
  77. package/src/file-serving/static-files.ts +0 -581
  78. package/src/index.ts +0 -14
  79. package/src/middleware/auth.ts +0 -220
  80. package/src/middleware/content_security_policy.ts +0 -215
  81. package/src/middleware/cors.ts +0 -74
  82. package/src/middleware/csrf.ts +0 -118
  83. package/src/middleware/ddos_protection.ts +0 -255
  84. package/src/middleware/file_security.ts +0 -191
  85. package/src/middleware/file_upload.ts +0 -275
  86. package/src/middleware/helmet.ts +0 -268
  87. package/src/middleware/index.ts +0 -117
  88. package/src/middleware/input_validation.ts +0 -449
  89. package/src/middleware/json_body.ts +0 -37
  90. package/src/middleware/performance_alerting.ts +0 -538
  91. package/src/middleware/performance_dashboard.ts +0 -661
  92. package/src/middleware/performance_monitor.ts +0 -943
  93. package/src/middleware/pipeline.ts +0 -489
  94. package/src/middleware/rate_limit.ts +0 -245
  95. package/src/middleware/request_id.ts +0 -36
  96. package/src/middleware/request_signing.ts +0 -636
  97. package/src/middleware/request_tracer.ts +0 -636
  98. package/src/middleware/response_cache.ts +0 -743
  99. package/src/middleware/security.ts +0 -482
  100. package/src/middleware/security_suite.ts +0 -257
  101. package/src/middleware/session.ts +0 -91
  102. package/src/model-binding/index.ts +0 -18
  103. package/src/model-binding/model-middleware.ts +0 -425
  104. package/src/model-binding/model-registry.ts +0 -550
  105. package/src/model-binding.ts +0 -370
  106. package/src/model-resolver-factory.ts +0 -106
  107. package/src/observability/correlation.ts +0 -691
  108. package/src/observability/health-checks.ts +0 -729
  109. package/src/observability/index.ts +0 -184
  110. package/src/observability/integration.ts +0 -548
  111. package/src/observability/metrics.ts +0 -753
  112. package/src/observability/tracing.ts +0 -638
  113. package/src/optimization/bun-utilities.ts +0 -778
  114. package/src/query-builder-integration.ts +0 -137
  115. package/src/request/context.ts +0 -62
  116. package/src/request/enhanced-request.ts +0 -857
  117. package/src/request/macros.ts +0 -688
  118. package/src/response/macros.ts +0 -665
  119. package/src/response/response-factory.ts +0 -596
  120. package/src/router/api-routes.ts +0 -243
  121. package/src/router/file-based-routing.ts +0 -690
  122. package/src/router/file-streaming.ts +0 -383
  123. package/src/router/fluent-router.ts +0 -927
  124. package/src/router/fluent-routing.ts +0 -797
  125. package/src/router/group-organization.ts +0 -213
  126. package/src/router/handler-resolver.ts +0 -291
  127. package/src/router/http-methods.ts +0 -377
  128. package/src/router/index.ts +0 -187
  129. package/src/router/middleware-groups.ts +0 -222
  130. package/src/router/middleware-integration.ts +0 -399
  131. package/src/router/middleware.ts +0 -231
  132. package/src/router/model-binding.ts +0 -215
  133. package/src/router/optimized-route-matching.ts +0 -253
  134. package/src/router/route-building.ts +0 -221
  135. package/src/router/route-compiler.ts +0 -702
  136. package/src/router/route-matching.ts +0 -349
  137. package/src/router/route-trie.ts +0 -464
  138. package/src/router/router.ts +0 -1604
  139. package/src/router/server.ts +0 -462
  140. package/src/router/validation-integration.ts +0 -443
  141. package/src/router/view-rendering.ts +0 -233
  142. package/src/router/websocket.ts +0 -100
  143. package/src/routing/route-caching.ts +0 -402
  144. package/src/routing/route-throttling.ts +0 -469
  145. package/src/routing/subdomain-routing.ts +0 -492
  146. package/src/session/database-store.ts +0 -109
  147. package/src/session/file-store.ts +0 -148
  148. package/src/session/index.ts +0 -244
  149. package/src/session/memory-store.ts +0 -88
  150. package/src/session/redis-store.ts +0 -93
  151. package/src/streaming/index.ts +0 -17
  152. package/src/streaming/sse-handler.ts +0 -482
  153. package/src/streaming/stream-handler.ts +0 -552
  154. package/src/testing/auth-testing.ts +0 -446
  155. package/src/testing/file-upload-testing.ts +0 -543
  156. package/src/testing/index.ts +0 -10
  157. package/src/testing/middleware-testing.ts +0 -322
  158. package/src/testing/model-binding-testing.ts +0 -645
  159. package/src/testing/performance-testing.ts +0 -738
  160. package/src/testing/test-client.ts +0 -310
  161. package/src/testing/test-request.ts +0 -315
  162. package/src/testing/test-response.ts +0 -332
  163. package/src/testing/types.ts +0 -224
  164. package/src/testing/websocket-testing.ts +0 -590
  165. package/src/types/controller-types.ts +0 -385
  166. package/src/types/core.ts +0 -683
  167. package/src/types/middleware-types.ts +0 -419
  168. package/src/types/request-response-augmentation.ts +0 -489
  169. package/src/types/route-inference.ts +0 -357
  170. package/src/types.ts +0 -2067
  171. package/src/url.ts +0 -126
  172. package/src/utils/index.ts +0 -1
  173. package/src/utils/query-preservation.ts +0 -201
  174. package/src/utils.ts +0 -392
  175. package/src/validation/validator.ts +0 -685
  176. package/src/websocket/clustering.ts +0 -762
@@ -172,7 +172,7 @@ export declare const wsAssertions: {
172
172
  /**
173
173
  * Assert message type
174
174
  */
175
- messageType: (tester: WebSocketTester, index: number, expectedType: "text" | "binary") => void;
175
+ messageType: (tester: WebSocketTester, index: number, expectedType: 'text' | 'binary') => void;
176
176
  /**
177
177
  * Assert ready state
178
178
  */
@@ -4,7 +4,7 @@
4
4
  * Advanced TypeScript utilities for type-safe middleware with generic constraints
5
5
  */
6
6
  import type { RouteHandler, TypedRequest } from './route-inference';
7
- export interface TypedMiddleware<TInput = any, TOutput = TInput, _TContext = object, TNext = any> {
7
+ export interface TypedMiddleware<TInput = Request, TOutput = Response, _TContext = object, TNext = () => Promise<TOutput>> {
8
8
  (request: TInput, next: TNext): Promise<TOutput> | TOutput;
9
9
  }
10
10
  export type AugmentContext<TBase, TAddition> = TBase & TAddition;
@@ -3,7 +3,13 @@
3
3
  *
4
4
  * Advanced TypeScript utilities for inferring route parameter types from URL patterns
5
5
  */
6
- export type ExtractRouteParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
6
+ /** Strip an inline constraint from a brace parameter: `id:[0-9]+` → `id` */
7
+ type StripInlineConstraint<T extends string> = T extends `${infer Name}:${string}` ? Name : T;
8
+ export type ExtractRouteParams<T extends string> = T extends `${string}{${infer Param}}${infer Rest}` ? (Param extends `${infer Inner}?` ? {
9
+ [K in StripInlineConstraint<Inner>]?: string;
10
+ } : {
11
+ [K in StripInlineConstraint<Param>]: string;
12
+ }) & ExtractRouteParams<Rest> : T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
7
13
  [K in Param]: string;
8
14
  } & ExtractRouteParams<`/${Rest}`> : T extends `${infer _Start}:${infer Param}?${infer Rest}` ? {
9
15
  [K in Param]?: string;
@@ -100,7 +106,7 @@ export interface RouteGroup<TPrefix extends string = '', TContext = object> {
100
106
  middleware?: TypedMiddleware<any, any, any, TContext>[];
101
107
  routes: TypedRoute<any, any, any, TContext>[];
102
108
  }
103
- export interface TypedMiddleware<TRequest = any, TResponse = any, TNext = any, _TContext = Record<string, never>> {
109
+ export interface TypedMiddleware<TRequest = Request, TResponse = Response, TNext = () => Promise<TResponse>, _TContext = Record<string, never>> {
104
110
  (request: TRequest, next: TNext): Promise<TResponse> | TResponse;
105
111
  }
106
112
  export interface RouteBuilder<TContext = object> {
@@ -166,3 +172,4 @@ export interface GenerateOpenAPISchema<T extends TypedRoute<any, any, any, any>>
166
172
  export type AssertEqual<T, U> = T extends U ? U extends T ? true : false : false;
167
173
  export type AssertExtends<T, U> = T extends U ? true : false;
168
174
  export type AssertNotEqual<T, U> = AssertEqual<T, U> extends true ? false : true;
175
+ export {};
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Server } from 'bun';
2
2
  import type { Router } from './router/router';
3
+ import type { SessionManager } from './session/index';
3
4
  import type { QueryPreservationConfig } from './utils/query-preservation';
4
5
  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
6
  export type { QueryPreservationConfig } from './utils/query-preservation';
@@ -702,6 +703,12 @@ export interface EnhancedRequest extends Request, Omit<RequestMacroMethods, 'ip'
702
703
  * Parsed JSON body (if Content-Type is application/json)
703
704
  */
704
705
  jsonBody?: Record<string, unknown>;
706
+ /**
707
+ * Raw unparsed request body cache, populated on first `rawBody()` read (or up
708
+ * front by a framework body parser). Kept so webhook signature checks get the
709
+ * exact bytes the client sent.
710
+ */
711
+ _rawBody?: string;
705
712
  /**
706
713
  * Form body data (if Content-Type is multipart/form-data or application/x-www-form-urlencoded)
707
714
  */
@@ -711,9 +718,11 @@ export interface EnhancedRequest extends Request, Omit<RequestMacroMethods, 'ip'
711
718
  */
712
719
  files?: UploadedFile[];
713
720
  /**
714
- * Session data (if session middleware is used)
721
+ * Session for the current request. The built-in session middleware
722
+ * attaches a `SessionManager` (with `get`/`set`/`flash`/… methods);
723
+ * testing utilities may attach plain `SessionData`.
715
724
  */
716
- session?: SessionData;
725
+ session?: SessionManager | SessionData;
717
726
  /**
718
727
  * User data (if authentication middleware is used)
719
728
  */
@@ -936,6 +945,13 @@ export interface Route {
936
945
  pattern?: {
937
946
  exec: (url: URL) => PatternMatchResult | null;
938
947
  };
948
+ /**
949
+ * Set to `false` (via `router.withoutNativeDispatch()`) to keep this
950
+ * route on the fetch-handler matcher even when the server runs with
951
+ * `nativeRoutes: true` — e.g. when it must respect registration-order
952
+ * precedence against an overlapping pattern.
953
+ */
954
+ nativeDispatch?: boolean;
939
955
  }
940
956
  /**
941
957
  * WebSocket handler configuration
@@ -967,6 +983,22 @@ export interface ServerOptions<T extends WebSocketData = WebSocketData> extends
967
983
  * These bypass the fetch handler entirely for zero-allocation serving (~15% faster).
968
984
  */
969
985
  static?: Record<string, Response>;
986
+ /**
987
+ * Opt-in: register compatible routes with `Bun.serve`'s native router
988
+ * (`routes`), skipping the fetch handler's URL parsing and route
989
+ * matching for them. Compatible means: standard HTTP method, no
990
+ * domain scoping, no `where()`/inline constraints, no optional
991
+ * params, and `{param}`s spanning whole segments. Everything else —
992
+ * incompatible routes, 404/405 handling, HEAD fallback, the generic
993
+ * OPTIONS preflight — still flows through the fetch handler with
994
+ * identical semantics.
995
+ *
996
+ * Caveat: Bun matches by specificity (exact > param > wildcard).
997
+ * Apps that rely on registration order between same-shape overlapping
998
+ * patterns should leave this off. Routes registered after `serve()`
999
+ * only join the native table after `reload()`.
1000
+ */
1001
+ nativeRoutes?: boolean;
970
1002
  /**
971
1003
  * Development mode options for Bun's dev server.
972
1004
  * When true, enables HMR and development features.
@@ -1085,11 +1117,30 @@ export type MiddlewareWithParams<T extends string = string> = T | `${T}:${string
1085
1117
  */
1086
1118
  export type RouteParam<T extends string> = T extends `{${infer P}}` ? P : never;
1087
1119
  /**
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;
1120
+ * Strip an inline constraint from a parameter token:
1121
+ * `id:[0-9]+` → `id`, `slug` → `slug`
1122
+ */
1123
+ export type ExtractParamName<T extends string> = T extends `${infer Name}:${string}` ? Name : T;
1124
+ /**
1125
+ * Extract parameters from a route path into a narrowly-typed object.
1126
+ *
1127
+ * Handles the full parameter grammar:
1128
+ * - `{id}` → `{ id: string }`
1129
+ * - `{id?}` (optional) → `{ id?: string }`
1130
+ * - `{id:[0-9]+}` (inline constraint) → `{ id: string }`
1131
+ * - trailing `*` wildcard → `{ wildcard: string }`
1132
+ *
1133
+ * @example
1134
+ * type P = ExtractRouteParams<'/users/{userId}/posts/{slug?}'>
1135
+ * // ^? { userId: string } & { slug?: string }
1136
+ */
1137
+ export type ExtractRouteParams<T extends string> = T extends `${string}{${infer Param}}${infer Rest}` ? (Param extends `${infer Inner}?` ? {
1138
+ [K in ExtractParamName<Inner>]?: string;
1139
+ } : {
1140
+ [K in ExtractParamName<Param>]: string;
1141
+ }) & ExtractRouteParams<Rest> : T extends `${string}*${string}` ? {
1142
+ wildcard: string;
1143
+ } : object;
1093
1144
  /**
1094
1145
  * Route method constraints
1095
1146
  */
@@ -1520,8 +1571,8 @@ export interface StreamingOptions {
1520
1571
  /**
1521
1572
  * SSE (Server-Sent Events) data structure
1522
1573
  */
1523
- export interface SSEData {
1524
- data: any;
1574
+ export interface SSEData<T = unknown> {
1575
+ data: T;
1525
1576
  event?: string;
1526
1577
  id?: string;
1527
1578
  retry?: number;
@@ -1701,6 +1752,8 @@ export interface RequestMacroMethods {
1701
1752
  username: string;
1702
1753
  password: string;
1703
1754
  } | null;
1755
+ /** Raw unparsed request body as a string (cached). Needed for webhook signature verification (Stripe/GitHub/Slack), where a re-serialized jsonBody won't match the HMAC. */
1756
+ rawBody: () => Promise<string>;
1704
1757
  hasHeader: (name: string) => boolean;
1705
1758
  header: (name: string, defaultValue?: string) => string | null;
1706
1759
  allHeaders: () => Record<string, string>;
package/dist/utils.d.ts CHANGED
@@ -66,4 +66,4 @@ export declare function resolveViewPath(viewName: string, viewsPath: string, ext
66
66
  * @param template The HTML template string
67
67
  * @param data The data to inject into the template
68
68
  */
69
- export declare function processHtmlTemplate(template: string, data: Record<string, any>): string;
69
+ export declare function processHtmlTemplate(template: string, data: Record<string, unknown>): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/bun-router",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.18",
5
5
  "description": "A fast, type-safe router for Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -28,6 +28,11 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "import": "./dist/index.js"
30
30
  },
31
+ "./container": {
32
+ "bun": "./dist/container/index.js",
33
+ "types": "./dist/container/index.d.ts",
34
+ "import": "./dist/container/index.js"
35
+ },
31
36
  "./*": {
32
37
  "bun": "./dist/*",
33
38
  "import": "./dist/*"
@@ -40,6 +45,11 @@
40
45
  "types": "./dist/index.d.ts",
41
46
  "import": "./dist/index.js"
42
47
  },
48
+ "./container": {
49
+ "bun": "./dist/container/index.js",
50
+ "types": "./dist/container/index.d.ts",
51
+ "import": "./dist/container/index.js"
52
+ },
43
53
  "./*": {
44
54
  "bun": "./dist/*",
45
55
  "import": "./dist/*"
@@ -54,8 +64,7 @@
54
64
  },
55
65
  "files": [
56
66
  "README.md",
57
- "dist",
58
- "src"
67
+ "dist"
59
68
  ],
60
69
  "scripts": {
61
70
  "build": "bun --bun build.ts && bun run compile",
@@ -1,315 +0,0 @@
1
- /**
2
- * Fluent Routing Extensions
3
- *
4
- * Implements fluent routing patterns with full TypeScript support
5
- */
6
- import type { EnhancedRequest, MiddlewareHandler, Route, RouteHandler } from '../types';
7
- import type { Router } from './router';
8
- /**
9
- * Controller class interface
10
- */
11
- export interface ControllerClass {
12
- new (): Controller;
13
- }
14
- /**
15
- * Base controller interface
16
- */
17
- export interface Controller {
18
- [key: string]: RouteHandler | unknown;
19
- }
20
- /**
21
- * Resource controller methods
22
- */
23
- export type ResourceMethod = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
24
- /**
25
- * API resource methods (no create/edit views)
26
- */
27
- export type ApiResourceMethod = 'index' | 'store' | 'show' | 'update' | 'destroy';
28
- /**
29
- * Singleton resource methods
30
- */
31
- export type SingletonMethod = 'show' | 'edit' | 'update';
32
- /**
33
- * Resource configuration
34
- */
35
- export interface ResourceOptions {
36
- only?: ResourceMethod[];
37
- except?: ResourceMethod[];
38
- middleware?: (string | MiddlewareHandler)[];
39
- names?: Partial<Record<ResourceMethod, string>>;
40
- parameters?: Record<string, string>;
41
- shallow?: boolean;
42
- }
43
- /**
44
- * Route builder for fluent API
45
- */
46
- export interface FluentRoute {
47
- name: (name: string) => FluentRoute;
48
- middleware: (...middleware: (string | MiddlewareHandler)[]) => FluentRoute;
49
- withoutMiddleware: (...middleware: string[]) => FluentRoute;
50
- where: (param: string, pattern: string | RegExp) => FluentRoute;
51
- whereNumber: (param: string) => FluentRoute;
52
- whereAlpha: (param: string) => FluentRoute;
53
- whereAlphaNumeric: (param: string) => FluentRoute;
54
- whereUuid: (param: string) => FluentRoute;
55
- whereSlug: (param: string) => FluentRoute;
56
- can: (ability: string, model?: string) => FluentRoute;
57
- missing: (handler: (req: EnhancedRequest) => Response) => FluentRoute;
58
- withTrashed: () => FluentRoute;
59
- scopeBindings: () => FluentRoute;
60
- }
61
- /**
62
- * Group builder for fluent API
63
- */
64
- export interface GroupBuilder {
65
- prefix: (prefix: string) => GroupBuilder;
66
- name: (name: string) => GroupBuilder;
67
- middleware: (...middleware: (string | MiddlewareHandler)[]) => GroupBuilder;
68
- domain: (domain: string) => GroupBuilder;
69
- controller: (controller: ControllerClass) => GroupBuilder;
70
- routes: (callback: (router: FluentRouter) => void) => void;
71
- }
72
- /**
73
- * Fluent router with chainable API
74
- */
75
- export declare class FluentRouter {
76
- private router;
77
- private currentPrefix;
78
- private currentNamePrefix;
79
- private currentMiddleware;
80
- private currentDomain;
81
- private currentController;
82
- private excludedMiddleware;
83
- constructor(router: Router);
84
- /**
85
- * Register a GET route
86
- */
87
- get(path: string, handler: RouteHandler | string | Response): FluentRouteBuilder;
88
- /**
89
- * Register a POST route
90
- */
91
- post(path: string, handler: RouteHandler | string): FluentRouteBuilder;
92
- /**
93
- * Register a PUT route
94
- */
95
- put(path: string, handler: RouteHandler | string): FluentRouteBuilder;
96
- /**
97
- * Register a PATCH route
98
- */
99
- patch(path: string, handler: RouteHandler | string): FluentRouteBuilder;
100
- /**
101
- * Register a DELETE route
102
- */
103
- delete(path: string, handler: RouteHandler | string): FluentRouteBuilder;
104
- /**
105
- * Register an OPTIONS route
106
- */
107
- options(path: string, handler: RouteHandler | string): FluentRouteBuilder;
108
- /**
109
- * Register a route for any HTTP method
110
- */
111
- any(path: string, handler: RouteHandler | string): FluentRouteBuilder;
112
- /**
113
- * Register a route for multiple HTTP methods
114
- */
115
- match(methods: string[], path: string, handler: RouteHandler | string): FluentRouteBuilder;
116
- /**
117
- * Register a resource controller
118
- */
119
- resource(name: string, Controller: ControllerClass, options?: ResourceOptions): this;
120
- /**
121
- * Register an API resource controller (no create/edit views)
122
- */
123
- apiResource(name: string, controller: ControllerClass, options?: ResourceOptions): this;
124
- /**
125
- * Register a singleton resource (no index, create, store, destroy)
126
- */
127
- singleton(name: string, Controller: ControllerClass, options?: ResourceOptions): this;
128
- /**
129
- * Create a route group with prefix
130
- */
131
- prefix(prefix: string): GroupBuilderImpl;
132
- /**
133
- * Create a route group with name prefix
134
- */
135
- name(namePrefix: string): GroupBuilderImpl;
136
- /**
137
- * Create a route group with middleware
138
- */
139
- middleware(...middleware: (string | MiddlewareHandler)[]): GroupBuilderImpl;
140
- /**
141
- * Create a route group for a domain
142
- */
143
- domain(domain: string): GroupBuilderImpl;
144
- /**
145
- * Create a route group with a controller
146
- */
147
- controller(controller: ControllerClass): GroupBuilderImpl;
148
- /**
149
- * Create a route group
150
- */
151
- group(options: GroupOptions, callback: (router: FluentRouter) => void): this;
152
- /**
153
- * Check if a named route exists
154
- */
155
- has(name: string): boolean;
156
- /**
157
- * Get the current route (from request context)
158
- */
159
- current(): Route | null;
160
- /**
161
- * Get the current route name
162
- */
163
- currentRouteName(): string | null;
164
- /**
165
- * Get URL for a named route
166
- */
167
- route(name: string, params?: Record<string, string | number>): string;
168
- /**
169
- * Register a fallback route
170
- */
171
- fallback(handler: RouteHandler): this;
172
- private addRoute;
173
- /**
174
- * Create a pattern object for route matching
175
- */
176
- private createPattern;
177
- private buildPath;
178
- private buildMiddleware;
179
- private resolveHandler;
180
- private resolveMiddleware;
181
- private getResourceMethods;
182
- private getResourceRoute;
183
- private getSingletonRoute;
184
- }
185
- /**
186
- * Fluent route builder for chaining route configuration
187
- */
188
- export declare class FluentRouteBuilder implements FluentRoute {
189
- private router;
190
- private path;
191
- private method;
192
- private routeName;
193
- private routeMiddleware;
194
- private excludedMiddleware;
195
- private constraints;
196
- private missingHandler;
197
- private includeTrashed;
198
- private scopeBindingsEnabled;
199
- private ability;
200
- private abilityModel;
201
- constructor(router: Router, path: string, method: string);
202
- /**
203
- * Set the route name
204
- */
205
- name(name: string): this;
206
- /**
207
- * Add middleware to the route
208
- */
209
- middleware(...middleware: (string | MiddlewareHandler)[]): this;
210
- /**
211
- * Exclude middleware from the route
212
- */
213
- withoutMiddleware(...middleware: string[]): this;
214
- /**
215
- * Add a parameter constraint
216
- */
217
- where(param: string, pattern: string | RegExp): this;
218
- /**
219
- * Constrain parameter to numbers
220
- */
221
- whereNumber(param: string): this;
222
- /**
223
- * Constrain parameter to letters
224
- */
225
- whereAlpha(param: string): this;
226
- /**
227
- * Constrain parameter to alphanumeric
228
- */
229
- whereAlphaNumeric(param: string): this;
230
- /**
231
- * Constrain parameter to UUID
232
- */
233
- whereUuid(param: string): this;
234
- /**
235
- * Constrain parameter to slug format
236
- */
237
- whereSlug(param: string): this;
238
- /**
239
- * Add authorization check
240
- */
241
- can(ability: string, model?: string): this;
242
- /**
243
- * Handle missing model binding
244
- */
245
- missing(handler: (req: EnhancedRequest) => Response): this;
246
- /**
247
- * Include soft-deleted models
248
- */
249
- withTrashed(): this;
250
- /**
251
- * Enable scoped bindings
252
- */
253
- scopeBindings(): this;
254
- private findRoute;
255
- }
256
- interface GroupOptions {
257
- prefix?: string;
258
- as?: string;
259
- middleware?: (string | MiddlewareHandler)[];
260
- domain?: string;
261
- controller?: ControllerClass;
262
- }
263
- declare class GroupBuilderImpl implements GroupBuilder {
264
- private fluentRouter;
265
- private options;
266
- constructor(router: FluentRouter);
267
- prefix(prefix: string): this;
268
- name(name: string): this;
269
- middleware(...middleware: (string | MiddlewareHandler)[]): this;
270
- domain(domain: string): this;
271
- controller(controller: ControllerClass): this;
272
- routes(callback: (router: FluentRouter) => void): void;
273
- }
274
- /**
275
- * Extend Router with fluent routing methods
276
- */
277
- export declare function registerFluentRouting(RouterClass: typeof import('./router').Router): void;
278
- declare module './router' {
279
- interface Router {
280
- /**
281
- * Get fluent router instance
282
- */
283
- fluent: () => FluentRouter;
284
- /**
285
- * Register a controller-based resource
286
- * Note: Use `resourceController` to avoid conflict with existing `resource` method
287
- */
288
- resourceController: (name: string, controller: ControllerClass, options?: ResourceOptions) => Router;
289
- /**
290
- * Register an API resource controller (no create/edit views)
291
- */
292
- apiResourceController: (name: string, controller: ControllerClass, options?: ResourceOptions) => Router;
293
- /**
294
- * Register a singleton resource
295
- */
296
- singletonResource: (name: string, controller: ControllerClass, options?: ResourceOptions) => Router;
297
- /**
298
- * Check if a named route exists
299
- */
300
- hasRoute: (name: string) => boolean;
301
- /**
302
- * Get the current route
303
- */
304
- currentRoute: () => Route | null;
305
- /**
306
- * Get the current route name
307
- */
308
- currentRouteName: () => string | null;
309
- /**
310
- * Get URL for a named route
311
- */
312
- routeUrl: (name: string, params?: Record<string, string | number>) => string;
313
- }
314
- }
315
- export {};