@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
@@ -1,359 +0,0 @@
1
- /* eslint-disable ts/no-unsafe-function-type */
2
- /**
3
- * Modern Dependency Injection Decorators
4
- */
5
-
6
- import type { ResolutionContext } from './container'
7
- import { Container } from './container'
8
-
9
- // Metadata keys with explicit types
10
- export const INJECTABLE_METADATA_KEY: unique symbol = Symbol('injectable')
11
- export const INJECT_METADATA_KEY: unique symbol = Symbol('inject')
12
- export const OPTIONAL_METADATA_KEY: unique symbol = Symbol('optional')
13
- export const TAGGED_METADATA_KEY: unique symbol = Symbol('tagged')
14
- export const CONTROLLER_METADATA_KEY: unique symbol = Symbol('controller')
15
- export const ROUTE_METADATA_KEY: unique symbol = Symbol('route')
16
- export const MIDDLEWARE_METADATA_KEY: unique symbol = Symbol('middleware')
17
- export const PARAM_METADATA_KEY: unique symbol = Symbol('param')
18
-
19
- // Decorator metadata interfaces
20
- export interface InjectableMetadata {
21
- token?: string | symbol
22
- scope?: 'singleton' | 'transient' | 'scoped' | 'request'
23
- tags?: string[]
24
- }
25
-
26
- export interface InjectMetadata {
27
- token: string | symbol | Function
28
- optional?: boolean
29
- tags?: string[]
30
- when?: (context: ResolutionContext) => boolean
31
- }
32
-
33
- export interface ControllerMetadata {
34
- prefix?: string
35
- middleware?: Function[]
36
- tags?: string[]
37
- }
38
-
39
- export interface RouteMetadata {
40
- method: string
41
- path: string
42
- middleware?: Function[]
43
- tags?: string[]
44
- }
45
-
46
- export interface ParamMetadata {
47
- type: 'param' | 'query' | 'body' | 'header' | 'cookie'
48
- key?: string
49
- token?: string | symbol | Function
50
- optional?: boolean
51
- transform?: (value: any) => any
52
- validate?: (value: any) => boolean
53
- }
54
-
55
- /**
56
- * Injectable decorator - marks a class as injectable
57
- */
58
- export function Injectable(metadata: InjectableMetadata = {}): ClassDecorator {
59
- return (target: any) => {
60
- // Store metadata directly on the class
61
- target[INJECTABLE_METADATA_KEY] = metadata
62
- return target
63
- }
64
- }
65
-
66
- /**
67
- * Inject decorator - specifies dependency injection for constructor parameters
68
- */
69
- export function Inject(token: string | symbol | Function, options?: {
70
- optional?: boolean
71
- tags?: string[]
72
- when?: (context: ResolutionContext) => boolean
73
- }): ParameterDecorator {
74
- return function (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) {
75
- // For constructor parameter decorators, target is the prototype
76
- // We need to store metadata on the class constructor, not the prototype
77
- const classConstructor = target.constructor === Function ? target : target.constructor
78
-
79
- if (!classConstructor[INJECT_METADATA_KEY]) {
80
- classConstructor[INJECT_METADATA_KEY] = []
81
- }
82
- const metadata: InjectMetadata = {
83
- token,
84
- optional: options?.optional,
85
- tags: options?.tags,
86
- when: options?.when,
87
- }
88
- classConstructor[INJECT_METADATA_KEY][parameterIndex] = metadata
89
- }
90
- }
91
-
92
- /**
93
- * Optional decorator - marks a dependency as optional
94
- */
95
- export function Optional(): ParameterDecorator {
96
- return (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) => {
97
- if (!target[OPTIONAL_METADATA_KEY]) {
98
- target[OPTIONAL_METADATA_KEY] = []
99
- }
100
- target[OPTIONAL_METADATA_KEY][parameterIndex] = true
101
- }
102
- }
103
-
104
- /**
105
- * Tagged decorator - injects services with specific tags
106
- */
107
- export function Tagged(tag: string): ParameterDecorator {
108
- return function (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) {
109
- if (!target[TAGGED_METADATA_KEY]) {
110
- target[TAGGED_METADATA_KEY] = []
111
- }
112
- target[TAGGED_METADATA_KEY][parameterIndex] = tag
113
- }
114
- }
115
-
116
- /**
117
- * Controller decorator - marks a class as a controller
118
- */
119
- export function Controller(prefix?: string, options?: {
120
- middleware?: Function[]
121
- tags?: string[]
122
- }): ClassDecorator {
123
- return function (target: any) {
124
- const metadata: ControllerMetadata = {
125
- prefix: prefix || '',
126
- middleware: options?.middleware || [],
127
- tags: options?.tags || [],
128
- }
129
- target[CONTROLLER_METADATA_KEY] = metadata
130
- return target
131
- }
132
- }
133
-
134
- /**
135
- * HTTP method decorators
136
- */
137
- export function Get(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
138
- return createRouteDecorator('GET', path, options)
139
- }
140
-
141
- export function Post(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
142
- return createRouteDecorator('POST', path, options)
143
- }
144
-
145
- export function Put(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
146
- return createRouteDecorator('PUT', path, options)
147
- }
148
-
149
- export function Delete(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
150
- return createRouteDecorator('DELETE', path, options)
151
- }
152
-
153
- export function Patch(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
154
- return createRouteDecorator('PATCH', path, options)
155
- }
156
-
157
- export function Options(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
158
- return createRouteDecorator('OPTIONS', path, options)
159
- }
160
-
161
- export function Head(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
162
- return createRouteDecorator('HEAD', path, options)
163
- }
164
-
165
- function createRouteDecorator(method: string, path: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
166
- return function (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
167
- if (!target.constructor[ROUTE_METADATA_KEY]) {
168
- target.constructor[ROUTE_METADATA_KEY] = []
169
- }
170
-
171
- const metadata: RouteMetadata = {
172
- method,
173
- path,
174
- middleware: options?.middleware || [],
175
- tags: options?.tags || [],
176
- }
177
-
178
- target.constructor[ROUTE_METADATA_KEY].push({
179
- ...metadata,
180
- propertyKey,
181
- handler: descriptor.value,
182
- })
183
-
184
- return descriptor
185
- }
186
- }
187
-
188
- /**
189
- * UseMiddleware decorator - applies middleware to a class or method
190
- */
191
- export function UseMiddleware(...middleware: Function[]): ClassDecorator & MethodDecorator {
192
- return function (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) {
193
- if (propertyKey && descriptor) {
194
- // Method decorator
195
- if (!target.constructor[MIDDLEWARE_METADATA_KEY]) {
196
- target.constructor[MIDDLEWARE_METADATA_KEY] = new Map()
197
- }
198
- target.constructor[MIDDLEWARE_METADATA_KEY].set(propertyKey, middleware)
199
- }
200
- else {
201
- // Class decorator
202
- target[MIDDLEWARE_METADATA_KEY] = middleware
203
- }
204
- return descriptor || target
205
- }
206
- }
207
-
208
- /**
209
- * Parameter decorators for route handlers
210
- */
211
- export function Param(key?: string): ParameterDecorator {
212
- return createParamDecorator('param', key)
213
- }
214
-
215
- export function Query(key?: string): ParameterDecorator {
216
- return createParamDecorator('query', key)
217
- }
218
-
219
- export function Body(): ParameterDecorator {
220
- return createParamDecorator('body')
221
- }
222
-
223
- export function Header(key?: string): ParameterDecorator {
224
- return createParamDecorator('header', key)
225
- }
226
-
227
- export function Cookie(key?: string): ParameterDecorator {
228
- return createParamDecorator('cookie', key)
229
- }
230
-
231
- export function InjectParam(token: string | symbol | Function): ParameterDecorator {
232
- return createParamDecorator('param', undefined, token)
233
- }
234
-
235
- function createParamDecorator(
236
- type: 'param' | 'query' | 'body' | 'header' | 'cookie',
237
- key?: string,
238
- token?: string | symbol | Function,
239
- ): ParameterDecorator {
240
- return function (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) {
241
- if (!target.constructor[PARAM_METADATA_KEY]) {
242
- target.constructor[PARAM_METADATA_KEY] = new Map()
243
- }
244
-
245
- if (!target.constructor[PARAM_METADATA_KEY].has(propertyKey)) {
246
- target.constructor[PARAM_METADATA_KEY].set(propertyKey, [])
247
- }
248
-
249
- const metadata: ParamMetadata = {
250
- type,
251
- key,
252
- token,
253
- }
254
-
255
- target.constructor[PARAM_METADATA_KEY].get(propertyKey)[parameterIndex] = metadata
256
- }
257
- }
258
-
259
- /**
260
- * Metadata reader utility class
261
- */
262
- export class MetadataReader {
263
- static getInjectableMetadata(target: Function): InjectableMetadata | undefined {
264
- return (target as any)[INJECTABLE_METADATA_KEY]
265
- }
266
-
267
- static getInjectMetadata(target: Function): InjectMetadata[] {
268
- return (target as any)[INJECT_METADATA_KEY] || []
269
- }
270
-
271
- static getOptionalMetadata(target: Function): boolean[] {
272
- return (target as any)[OPTIONAL_METADATA_KEY] || []
273
- }
274
-
275
- static getTaggedMetadata(target: Function): string[] {
276
- return (target as any)[TAGGED_METADATA_KEY] || []
277
- }
278
-
279
- static getControllerMetadata(target: Function): ControllerMetadata | undefined {
280
- return (target as any)[CONTROLLER_METADATA_KEY]
281
- }
282
-
283
- static getAllRoutes(target: Function): any[] {
284
- return (target as any)[ROUTE_METADATA_KEY] || []
285
- }
286
-
287
- static getMiddlewareMetadata(target: Function, propertyKey?: string | symbol): Function[] {
288
- if (propertyKey) {
289
- const methodMiddleware = (target as any)[MIDDLEWARE_METADATA_KEY]?.get(propertyKey)
290
- return methodMiddleware || []
291
- }
292
- return (target as any)[MIDDLEWARE_METADATA_KEY] || []
293
- }
294
-
295
- static getParamMetadata(target: Function, propertyKey: string | symbol): ParamMetadata[] {
296
- return (target as any)[PARAM_METADATA_KEY]?.get(propertyKey) || []
297
- }
298
- }
299
-
300
- /**
301
- * Modern Decorator Container
302
- */
303
- export class DecoratorContainer extends Container {
304
- /**
305
- * Register a controller with automatic route discovery
306
- */
307
- registerController(controllerClass: Function): void {
308
- const metadata = MetadataReader.getControllerMetadata(controllerClass)
309
- if (!metadata) {
310
- throw new Error(`Class ${controllerClass.name} is not decorated with @Controller`)
311
- }
312
-
313
- // Register the controller as a service using the class constructor as token
314
- this.singleton(controllerClass, controllerClass as any)
315
-
316
- // Process routes
317
- const routes = MetadataReader.getAllRoutes(controllerClass)
318
- for (const _route of routes) {
319
- // Route registration logic would go here
320
- // This is a simplified version for the DI system
321
- }
322
- }
323
-
324
- /**
325
- * Enhanced resolve method that handles decorator metadata
326
- */
327
- resolve<T>(token: string | symbol | Function, context?: ResolutionContext): T {
328
- // Check if token is a class with injectable metadata
329
- if (typeof token === 'function') {
330
- const metadata = MetadataReader.getInjectableMetadata(token)
331
- if (metadata) {
332
- // Auto-register if not already registered
333
- try {
334
- // Try to resolve first to see if it exists
335
- return super.resolve<T>(token, context)
336
- }
337
- catch {
338
- // If it doesn't exist, register it
339
- const scope = metadata.scope || 'transient'
340
- switch (scope) {
341
- case 'singleton':
342
- this.singleton(token, token as any)
343
- break
344
- case 'transient':
345
- this.transient(token, token as any)
346
- break
347
- default:
348
- this.transient(token, token as any)
349
- }
350
- }
351
- }
352
- }
353
-
354
- return super.resolve<T>(token, context)
355
- }
356
- }
357
-
358
- // Export a default instance
359
- export const decoratorContainer: DecoratorContainer = new DecoratorContainer()