@stacksjs/bun-router 0.0.17 → 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 (146) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/container/service-provider.d.ts +3 -3
  3. package/dist/development/performance-profiler.d.ts +3 -3
  4. package/dist/development/route-debugger.d.ts +1 -1
  5. package/dist/development/route-inspector.d.ts +2 -2
  6. package/dist/observability/integration.d.ts +1 -1
  7. package/dist/response/macros.d.ts +1 -1
  8. package/dist/router/index.d.ts +7 -7
  9. package/dist/router/router.d.ts +0 -32
  10. package/dist/testing/performance-testing.d.ts +2 -2
  11. package/dist/testing/test-client.d.ts +1 -1
  12. package/dist/testing/websocket-testing.d.ts +1 -1
  13. package/package.json +2 -3
  14. package/src/auth.ts +0 -489
  15. package/src/cache/lru-cache.ts +0 -457
  16. package/src/cache/middleware-memoization.ts +0 -531
  17. package/src/cache/route-cache-warmer.ts +0 -486
  18. package/src/cache/sqlite-cache.ts +0 -783
  19. package/src/cache/streaming-cache.ts +0 -572
  20. package/src/cli/colors.ts +0 -29
  21. package/src/cli/index.ts +0 -287
  22. package/src/cli/middleware.ts +0 -291
  23. package/src/cli/openapi.ts +0 -407
  24. package/src/cli/router.ts +0 -188
  25. package/src/cli/routes.ts +0 -265
  26. package/src/cli/utils.ts +0 -531
  27. package/src/cli.ts +0 -5
  28. package/src/config.ts +0 -322
  29. package/src/container/container.ts +0 -786
  30. package/src/container/contextual-binding.ts +0 -606
  31. package/src/container/decorators.ts +0 -368
  32. package/src/container/index.ts +0 -49
  33. package/src/container/service-provider.ts +0 -596
  34. package/src/development/hot-reload.ts +0 -673
  35. package/src/development/index.ts +0 -499
  36. package/src/development/performance-profiler.ts +0 -717
  37. package/src/development/route-debugger.ts +0 -527
  38. package/src/development/route-inspector.ts +0 -749
  39. package/src/development/typescript-utilities.ts +0 -682
  40. package/src/docs.ts +0 -397
  41. package/src/errors/circuit-breaker.ts +0 -733
  42. package/src/errors/error-handler.ts +0 -569
  43. package/src/errors/error-reporting.ts +0 -672
  44. package/src/errors/exceptions.ts +0 -536
  45. package/src/errors/graceful-degradation.ts +0 -623
  46. package/src/errors/index.ts +0 -21
  47. package/src/errors/router-errors.ts +0 -632
  48. package/src/file-serving/static-files.ts +0 -718
  49. package/src/index.ts +0 -66
  50. package/src/middleware/auth.ts +0 -220
  51. package/src/middleware/content_security_policy.ts +0 -215
  52. package/src/middleware/cors.ts +0 -142
  53. package/src/middleware/csrf.ts +0 -166
  54. package/src/middleware/ddos_protection.ts +0 -279
  55. package/src/middleware/file_security.ts +0 -191
  56. package/src/middleware/file_upload.ts +0 -275
  57. package/src/middleware/helmet.ts +0 -268
  58. package/src/middleware/index.ts +0 -117
  59. package/src/middleware/input_validation.ts +0 -453
  60. package/src/middleware/json_body.ts +0 -37
  61. package/src/middleware/performance_alerting.ts +0 -540
  62. package/src/middleware/performance_dashboard.ts +0 -661
  63. package/src/middleware/performance_monitor.ts +0 -945
  64. package/src/middleware/pipeline.ts +0 -489
  65. package/src/middleware/rate_limit.ts +0 -251
  66. package/src/middleware/request_id.ts +0 -36
  67. package/src/middleware/request_signing.ts +0 -638
  68. package/src/middleware/request_tracer.ts +0 -653
  69. package/src/middleware/response_cache.ts +0 -778
  70. package/src/middleware/security.ts +0 -482
  71. package/src/middleware/security_suite.ts +0 -257
  72. package/src/middleware/session.ts +0 -91
  73. package/src/model-binding/index.ts +0 -18
  74. package/src/model-binding/model-middleware.ts +0 -425
  75. package/src/model-binding/model-registry.ts +0 -550
  76. package/src/model-binding.ts +0 -370
  77. package/src/model-resolver-factory.ts +0 -106
  78. package/src/observability/correlation.ts +0 -691
  79. package/src/observability/health-checks.ts +0 -729
  80. package/src/observability/index.ts +0 -184
  81. package/src/observability/integration.ts +0 -548
  82. package/src/observability/metrics.ts +0 -753
  83. package/src/observability/tracing.ts +0 -638
  84. package/src/optimization/bun-utilities.ts +0 -778
  85. package/src/query-builder-integration.ts +0 -137
  86. package/src/request/context.ts +0 -109
  87. package/src/request/enhanced-request.ts +0 -876
  88. package/src/request/macros.ts +0 -822
  89. package/src/response/macros.ts +0 -665
  90. package/src/response/response-factory.ts +0 -596
  91. package/src/router/api-routes.ts +0 -243
  92. package/src/router/file-based-routing.ts +0 -697
  93. package/src/router/file-streaming.ts +0 -383
  94. package/src/router/fluent-routing.ts +0 -866
  95. package/src/router/group-organization.ts +0 -229
  96. package/src/router/handler-resolver.ts +0 -327
  97. package/src/router/http-methods.ts +0 -407
  98. package/src/router/index.ts +0 -193
  99. package/src/router/middleware-groups.ts +0 -222
  100. package/src/router/middleware-integration.ts +0 -399
  101. package/src/router/middleware.ts +0 -234
  102. package/src/router/model-binding.ts +0 -215
  103. package/src/router/optimized-route-matching.ts +0 -302
  104. package/src/router/route-building.ts +0 -221
  105. package/src/router/route-compiler.ts +0 -691
  106. package/src/router/route-matching.ts +0 -368
  107. package/src/router/route-trie.ts +0 -450
  108. package/src/router/router.ts +0 -1616
  109. package/src/router/server.ts +0 -684
  110. package/src/router/validation-integration.ts +0 -449
  111. package/src/router/view-rendering.ts +0 -233
  112. package/src/router/websocket.ts +0 -100
  113. package/src/routing/route-caching.ts +0 -402
  114. package/src/routing/route-throttling.ts +0 -469
  115. package/src/routing/subdomain-routing.ts +0 -492
  116. package/src/session/database-store.ts +0 -109
  117. package/src/session/file-store.ts +0 -148
  118. package/src/session/index.ts +0 -244
  119. package/src/session/memory-store.ts +0 -88
  120. package/src/session/redis-store.ts +0 -93
  121. package/src/streaming/index.ts +0 -17
  122. package/src/streaming/sse-handler.ts +0 -482
  123. package/src/streaming/stream-handler.ts +0 -552
  124. package/src/testing/auth-testing.ts +0 -448
  125. package/src/testing/file-upload-testing.ts +0 -543
  126. package/src/testing/index.ts +0 -10
  127. package/src/testing/middleware-testing.ts +0 -322
  128. package/src/testing/model-binding-testing.ts +0 -645
  129. package/src/testing/performance-testing.ts +0 -738
  130. package/src/testing/test-client.ts +0 -310
  131. package/src/testing/test-request.ts +0 -315
  132. package/src/testing/test-response.ts +0 -332
  133. package/src/testing/types.ts +0 -224
  134. package/src/testing/websocket-testing.ts +0 -590
  135. package/src/types/controller-types.ts +0 -385
  136. package/src/types/core.ts +0 -683
  137. package/src/types/middleware-types.ts +0 -422
  138. package/src/types/request-response-augmentation.ts +0 -489
  139. package/src/types/route-inference.ts +0 -372
  140. package/src/types.ts +0 -2123
  141. package/src/url.ts +0 -131
  142. package/src/utils/index.ts +0 -1
  143. package/src/utils/query-preservation.ts +0 -201
  144. package/src/utils.ts +0 -395
  145. package/src/validation/validator.ts +0 -688
  146. package/src/websocket/clustering.ts +0 -769
@@ -1,368 +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 {
8
- Container,
9
- INJECT_METADATA_KEY,
10
- INJECTABLE_METADATA_KEY,
11
- OPTIONAL_METADATA_KEY,
12
- TAGGED_METADATA_KEY,
13
- } from './container'
14
-
15
- // The injection metadata keys MUST be the container's own symbols — this
16
- // module previously declared its own `Symbol('inject')` etc., so metadata
17
- // written by `@Inject` was invisible to `Container.getConstructorDependencies`
18
- // (which reads with the container's symbols) and constructor injection
19
- // silently resolved nothing. Re-exported for backward compatibility.
20
- export { INJECT_METADATA_KEY, INJECTABLE_METADATA_KEY, OPTIONAL_METADATA_KEY, TAGGED_METADATA_KEY }
21
-
22
- // Decorator-specific metadata keys
23
- export const CONTROLLER_METADATA_KEY: unique symbol = Symbol('controller')
24
- export const ROUTE_METADATA_KEY: unique symbol = Symbol('route')
25
- export const MIDDLEWARE_METADATA_KEY: unique symbol = Symbol('middleware')
26
- export const PARAM_METADATA_KEY: unique symbol = Symbol('param')
27
-
28
- // Decorator metadata interfaces
29
- export interface InjectableMetadata {
30
- token?: string | symbol
31
- scope?: 'singleton' | 'transient' | 'scoped' | 'request'
32
- tags?: string[]
33
- }
34
-
35
- export interface InjectMetadata {
36
- token: string | symbol | Function
37
- optional?: boolean
38
- tags?: string[]
39
- when?: (context: ResolutionContext) => boolean
40
- }
41
-
42
- export interface ControllerMetadata {
43
- prefix?: string
44
- middleware?: Function[]
45
- tags?: string[]
46
- }
47
-
48
- export interface RouteMetadata {
49
- method: string
50
- path: string
51
- middleware?: Function[]
52
- tags?: string[]
53
- }
54
-
55
- export interface ParamMetadata {
56
- type: 'param' | 'query' | 'body' | 'header' | 'cookie'
57
- key?: string
58
- token?: string | symbol | Function
59
- optional?: boolean
60
- transform?: (value: any) => any
61
- validate?: (value: any) => boolean
62
- }
63
-
64
- /**
65
- * Injectable decorator - marks a class as injectable
66
- */
67
- export function Injectable(metadata: InjectableMetadata = {}): ClassDecorator {
68
- return (target: any) => {
69
- // Store metadata directly on the class
70
- target[INJECTABLE_METADATA_KEY] = metadata
71
- return target
72
- }
73
- }
74
-
75
- /**
76
- * Inject decorator - specifies dependency injection for constructor parameters
77
- */
78
- export function Inject(token: string | symbol | Function, options?: {
79
- optional?: boolean
80
- tags?: string[]
81
- when?: (context: ResolutionContext) => boolean
82
- }): ParameterDecorator {
83
- return function (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) {
84
- // For constructor parameter decorators, target is the prototype
85
- // We need to store metadata on the class constructor, not the prototype
86
- const classConstructor = target.constructor === Function ? target : target.constructor
87
-
88
- if (!classConstructor[INJECT_METADATA_KEY]) {
89
- classConstructor[INJECT_METADATA_KEY] = []
90
- }
91
- const metadata: InjectMetadata = {
92
- token,
93
- optional: options?.optional,
94
- tags: options?.tags,
95
- when: options?.when,
96
- }
97
- classConstructor[INJECT_METADATA_KEY][parameterIndex] = metadata
98
- }
99
- }
100
-
101
- /**
102
- * Optional decorator - marks a dependency as optional
103
- */
104
- export function Optional(): ParameterDecorator {
105
- return (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) => {
106
- if (!target[OPTIONAL_METADATA_KEY]) {
107
- target[OPTIONAL_METADATA_KEY] = []
108
- }
109
- target[OPTIONAL_METADATA_KEY][parameterIndex] = true
110
- }
111
- }
112
-
113
- /**
114
- * Tagged decorator - injects services with specific tags
115
- */
116
- export function Tagged(tag: string): ParameterDecorator {
117
- return function (target: any, _propertyKey: string | symbol | undefined, parameterIndex: number) {
118
- if (!target[TAGGED_METADATA_KEY]) {
119
- target[TAGGED_METADATA_KEY] = []
120
- }
121
- target[TAGGED_METADATA_KEY][parameterIndex] = tag
122
- }
123
- }
124
-
125
- /**
126
- * Controller decorator - marks a class as a controller
127
- */
128
- export function Controller(prefix?: string, options?: {
129
- middleware?: Function[]
130
- tags?: string[]
131
- }): ClassDecorator {
132
- return function (target: any) {
133
- const metadata: ControllerMetadata = {
134
- prefix: prefix || '',
135
- middleware: options?.middleware || [],
136
- tags: options?.tags || [],
137
- }
138
- target[CONTROLLER_METADATA_KEY] = metadata
139
- return target
140
- }
141
- }
142
-
143
- /**
144
- * HTTP method decorators
145
- */
146
- export function Get(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
147
- return createRouteDecorator('GET', path, options)
148
- }
149
-
150
- export function Post(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
151
- return createRouteDecorator('POST', path, options)
152
- }
153
-
154
- export function Put(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
155
- return createRouteDecorator('PUT', path, options)
156
- }
157
-
158
- export function Delete(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
159
- return createRouteDecorator('DELETE', path, options)
160
- }
161
-
162
- export function Patch(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
163
- return createRouteDecorator('PATCH', path, options)
164
- }
165
-
166
- export function Options(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
167
- return createRouteDecorator('OPTIONS', path, options)
168
- }
169
-
170
- export function Head(path: string = '', options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
171
- return createRouteDecorator('HEAD', path, options)
172
- }
173
-
174
- function createRouteDecorator(method: string, path: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator {
175
- return function (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
176
- if (!target.constructor[ROUTE_METADATA_KEY]) {
177
- target.constructor[ROUTE_METADATA_KEY] = []
178
- }
179
-
180
- const metadata: RouteMetadata = {
181
- method,
182
- path,
183
- middleware: options?.middleware || [],
184
- tags: options?.tags || [],
185
- }
186
-
187
- target.constructor[ROUTE_METADATA_KEY].push({
188
- ...metadata,
189
- propertyKey,
190
- handler: descriptor.value,
191
- })
192
-
193
- return descriptor
194
- }
195
- }
196
-
197
- /**
198
- * UseMiddleware decorator - applies middleware to a class or method
199
- */
200
- export function UseMiddleware(...middleware: Function[]): ClassDecorator & MethodDecorator {
201
- return function (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) {
202
- if (propertyKey && descriptor) {
203
- // Method decorator
204
- if (!target.constructor[MIDDLEWARE_METADATA_KEY]) {
205
- target.constructor[MIDDLEWARE_METADATA_KEY] = new Map()
206
- }
207
- target.constructor[MIDDLEWARE_METADATA_KEY].set(propertyKey, middleware)
208
- }
209
- else {
210
- // Class decorator
211
- target[MIDDLEWARE_METADATA_KEY] = middleware
212
- }
213
- return descriptor || target
214
- }
215
- }
216
-
217
- /**
218
- * Parameter decorators for route handlers
219
- */
220
- export function Param(key?: string): ParameterDecorator {
221
- return createParamDecorator('param', key)
222
- }
223
-
224
- export function Query(key?: string): ParameterDecorator {
225
- return createParamDecorator('query', key)
226
- }
227
-
228
- export function Body(): ParameterDecorator {
229
- return createParamDecorator('body')
230
- }
231
-
232
- export function Header(key?: string): ParameterDecorator {
233
- return createParamDecorator('header', key)
234
- }
235
-
236
- export function Cookie(key?: string): ParameterDecorator {
237
- return createParamDecorator('cookie', key)
238
- }
239
-
240
- export function InjectParam(token: string | symbol | Function): ParameterDecorator {
241
- return createParamDecorator('param', undefined, token)
242
- }
243
-
244
- function createParamDecorator(
245
- type: 'param' | 'query' | 'body' | 'header' | 'cookie',
246
- key?: string,
247
- token?: string | symbol | Function,
248
- ): ParameterDecorator {
249
- return function (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) {
250
- if (!target.constructor[PARAM_METADATA_KEY]) {
251
- target.constructor[PARAM_METADATA_KEY] = new Map()
252
- }
253
-
254
- if (!target.constructor[PARAM_METADATA_KEY].has(propertyKey)) {
255
- target.constructor[PARAM_METADATA_KEY].set(propertyKey, [])
256
- }
257
-
258
- const metadata: ParamMetadata = {
259
- type,
260
- key,
261
- token,
262
- }
263
-
264
- target.constructor[PARAM_METADATA_KEY].get(propertyKey)[parameterIndex] = metadata
265
- }
266
- }
267
-
268
- /**
269
- * Metadata reader utility class
270
- */
271
- export class MetadataReader {
272
- static getInjectableMetadata(target: Function): InjectableMetadata | undefined {
273
- return (target as any)[INJECTABLE_METADATA_KEY]
274
- }
275
-
276
- static getInjectMetadata(target: Function): InjectMetadata[] {
277
- return (target as any)[INJECT_METADATA_KEY] || []
278
- }
279
-
280
- static getOptionalMetadata(target: Function): boolean[] {
281
- return (target as any)[OPTIONAL_METADATA_KEY] || []
282
- }
283
-
284
- static getTaggedMetadata(target: Function): string[] {
285
- return (target as any)[TAGGED_METADATA_KEY] || []
286
- }
287
-
288
- static getControllerMetadata(target: Function): ControllerMetadata | undefined {
289
- return (target as any)[CONTROLLER_METADATA_KEY]
290
- }
291
-
292
- static getAllRoutes(target: Function): any[] {
293
- return (target as any)[ROUTE_METADATA_KEY] || []
294
- }
295
-
296
- static getMiddlewareMetadata(target: Function, propertyKey?: string | symbol): Function[] {
297
- if (propertyKey) {
298
- const methodMiddleware = (target as any)[MIDDLEWARE_METADATA_KEY]?.get(propertyKey)
299
- return methodMiddleware || []
300
- }
301
- return (target as any)[MIDDLEWARE_METADATA_KEY] || []
302
- }
303
-
304
- static getParamMetadata(target: Function, propertyKey: string | symbol): ParamMetadata[] {
305
- return (target as any)[PARAM_METADATA_KEY]?.get(propertyKey) || []
306
- }
307
- }
308
-
309
- /**
310
- * Modern Decorator Container
311
- */
312
- export class DecoratorContainer extends Container {
313
- /**
314
- * Register a controller with automatic route discovery
315
- */
316
- registerController(controllerClass: Function): void {
317
- const metadata = MetadataReader.getControllerMetadata(controllerClass)
318
- if (!metadata) {
319
- throw new Error(`Class ${controllerClass.name} is not decorated with @Controller`)
320
- }
321
-
322
- // Register the controller as a service using the class constructor as token
323
- this.singleton(controllerClass, controllerClass as any)
324
-
325
- // Process routes
326
- const routes = MetadataReader.getAllRoutes(controllerClass)
327
- for (const _route of routes) {
328
- // Route registration logic would go here
329
- // This is a simplified version for the DI system
330
- }
331
- }
332
-
333
- /**
334
- * Enhanced resolve method that handles decorator metadata
335
- */
336
- resolve<T>(token: string | symbol | Function, context?: ResolutionContext): T {
337
- // Check if token is a class with injectable metadata
338
- if (typeof token === 'function') {
339
- const metadata = MetadataReader.getInjectableMetadata(token)
340
- if (metadata) {
341
- // Auto-register if not already registered
342
- try {
343
- // Try to resolve first to see if it exists
344
- return super.resolve<T>(token, context)
345
- }
346
- catch {
347
- // If it doesn't exist, register it
348
- const scope = metadata.scope || 'transient'
349
- switch (scope) {
350
- case 'singleton':
351
- this.singleton(token, token as any)
352
- break
353
- case 'transient':
354
- this.transient(token, token as any)
355
- break
356
- default:
357
- this.transient(token, token as any)
358
- }
359
- }
360
- }
361
- }
362
-
363
- return super.resolve<T>(token, context)
364
- }
365
- }
366
-
367
- // Export a default instance
368
- export const decoratorContainer: DecoratorContainer = new DecoratorContainer()
@@ -1,49 +0,0 @@
1
- /**
2
- * Dependency-injection container — public entry point.
3
- *
4
- * ```ts
5
- * import { Container, createContainer, Inject, Injectable } from '@stacksjs/bun-router/container'
6
- * ```
7
- *
8
- * The core `Container` (and a few companions) are also re-exported from the
9
- * package root; the decorators live only here because their names (`Get`,
10
- * `Post`, `Controller`, …) would collide with the router's exports.
11
- */
12
-
13
- export * from './container'
14
-
15
- // Decorators. The duplicate `InjectableMetadata`/`InjectMetadata` interface
16
- // declarations stay out of the barrel — the canonical ones come from
17
- // `./container` above.
18
- export {
19
- Body,
20
- Controller,
21
- CONTROLLER_METADATA_KEY,
22
- Cookie,
23
- decoratorContainer,
24
- DecoratorContainer,
25
- Delete,
26
- Get,
27
- Head,
28
- Header,
29
- Inject,
30
- Injectable,
31
- InjectParam,
32
- MetadataReader,
33
- MIDDLEWARE_METADATA_KEY,
34
- Optional,
35
- Options,
36
- Param,
37
- PARAM_METADATA_KEY,
38
- Patch,
39
- Post,
40
- Put,
41
- Query,
42
- ROUTE_METADATA_KEY,
43
- Tagged,
44
- UseMiddleware,
45
- } from './decorators'
46
- export type { ControllerMetadata, ParamMetadata, RouteMetadata } from './decorators'
47
-
48
- export * from './contextual-binding'
49
- export * from './service-provider'