@stacksjs/bun-router 0.0.17 → 0.0.19

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 (153) hide show
  1. package/dist/chunk-2mx7fq49.js +4 -0
  2. package/dist/chunk-a8p83068.js +103 -0
  3. package/dist/{chunk-cgptvjdf.js → chunk-y3xq6wq6.js} +1 -1
  4. package/dist/cli.js +4 -3
  5. package/dist/container/index.js +1149 -211
  6. package/dist/container/service-provider.d.ts +3 -3
  7. package/dist/development/performance-profiler.d.ts +3 -3
  8. package/dist/development/route-debugger.d.ts +1 -1
  9. package/dist/development/route-inspector.d.ts +2 -2
  10. package/dist/index.js +369 -2209
  11. package/dist/observability/integration.d.ts +1 -1
  12. package/dist/response/macros.d.ts +1 -1
  13. package/dist/router/index.d.ts +7 -7
  14. package/dist/router/router.d.ts +0 -32
  15. package/dist/testing/performance-testing.d.ts +2 -2
  16. package/dist/testing/test-client.d.ts +1 -1
  17. package/dist/testing/websocket-testing.d.ts +1 -1
  18. package/package.json +7 -7
  19. package/dist/chunk-1ahs68ys.js +0 -18
  20. package/dist/chunk-g3ybefhg.js +0 -1923
  21. package/src/auth.ts +0 -489
  22. package/src/cache/lru-cache.ts +0 -457
  23. package/src/cache/middleware-memoization.ts +0 -531
  24. package/src/cache/route-cache-warmer.ts +0 -486
  25. package/src/cache/sqlite-cache.ts +0 -783
  26. package/src/cache/streaming-cache.ts +0 -572
  27. package/src/cli/colors.ts +0 -29
  28. package/src/cli/index.ts +0 -287
  29. package/src/cli/middleware.ts +0 -291
  30. package/src/cli/openapi.ts +0 -407
  31. package/src/cli/router.ts +0 -188
  32. package/src/cli/routes.ts +0 -265
  33. package/src/cli/utils.ts +0 -531
  34. package/src/cli.ts +0 -5
  35. package/src/config.ts +0 -322
  36. package/src/container/container.ts +0 -786
  37. package/src/container/contextual-binding.ts +0 -606
  38. package/src/container/decorators.ts +0 -368
  39. package/src/container/index.ts +0 -49
  40. package/src/container/service-provider.ts +0 -596
  41. package/src/development/hot-reload.ts +0 -673
  42. package/src/development/index.ts +0 -499
  43. package/src/development/performance-profiler.ts +0 -717
  44. package/src/development/route-debugger.ts +0 -527
  45. package/src/development/route-inspector.ts +0 -749
  46. package/src/development/typescript-utilities.ts +0 -682
  47. package/src/docs.ts +0 -397
  48. package/src/errors/circuit-breaker.ts +0 -733
  49. package/src/errors/error-handler.ts +0 -569
  50. package/src/errors/error-reporting.ts +0 -672
  51. package/src/errors/exceptions.ts +0 -536
  52. package/src/errors/graceful-degradation.ts +0 -623
  53. package/src/errors/index.ts +0 -21
  54. package/src/errors/router-errors.ts +0 -632
  55. package/src/file-serving/static-files.ts +0 -718
  56. package/src/index.ts +0 -66
  57. package/src/middleware/auth.ts +0 -220
  58. package/src/middleware/content_security_policy.ts +0 -215
  59. package/src/middleware/cors.ts +0 -142
  60. package/src/middleware/csrf.ts +0 -166
  61. package/src/middleware/ddos_protection.ts +0 -279
  62. package/src/middleware/file_security.ts +0 -191
  63. package/src/middleware/file_upload.ts +0 -275
  64. package/src/middleware/helmet.ts +0 -268
  65. package/src/middleware/index.ts +0 -117
  66. package/src/middleware/input_validation.ts +0 -453
  67. package/src/middleware/json_body.ts +0 -37
  68. package/src/middleware/performance_alerting.ts +0 -540
  69. package/src/middleware/performance_dashboard.ts +0 -661
  70. package/src/middleware/performance_monitor.ts +0 -945
  71. package/src/middleware/pipeline.ts +0 -489
  72. package/src/middleware/rate_limit.ts +0 -251
  73. package/src/middleware/request_id.ts +0 -36
  74. package/src/middleware/request_signing.ts +0 -638
  75. package/src/middleware/request_tracer.ts +0 -653
  76. package/src/middleware/response_cache.ts +0 -778
  77. package/src/middleware/security.ts +0 -482
  78. package/src/middleware/security_suite.ts +0 -257
  79. package/src/middleware/session.ts +0 -91
  80. package/src/model-binding/index.ts +0 -18
  81. package/src/model-binding/model-middleware.ts +0 -425
  82. package/src/model-binding/model-registry.ts +0 -550
  83. package/src/model-binding.ts +0 -370
  84. package/src/model-resolver-factory.ts +0 -106
  85. package/src/observability/correlation.ts +0 -691
  86. package/src/observability/health-checks.ts +0 -729
  87. package/src/observability/index.ts +0 -184
  88. package/src/observability/integration.ts +0 -548
  89. package/src/observability/metrics.ts +0 -753
  90. package/src/observability/tracing.ts +0 -638
  91. package/src/optimization/bun-utilities.ts +0 -778
  92. package/src/query-builder-integration.ts +0 -137
  93. package/src/request/context.ts +0 -109
  94. package/src/request/enhanced-request.ts +0 -876
  95. package/src/request/macros.ts +0 -822
  96. package/src/response/macros.ts +0 -665
  97. package/src/response/response-factory.ts +0 -596
  98. package/src/router/api-routes.ts +0 -243
  99. package/src/router/file-based-routing.ts +0 -697
  100. package/src/router/file-streaming.ts +0 -383
  101. package/src/router/fluent-routing.ts +0 -866
  102. package/src/router/group-organization.ts +0 -229
  103. package/src/router/handler-resolver.ts +0 -327
  104. package/src/router/http-methods.ts +0 -407
  105. package/src/router/index.ts +0 -193
  106. package/src/router/middleware-groups.ts +0 -222
  107. package/src/router/middleware-integration.ts +0 -399
  108. package/src/router/middleware.ts +0 -234
  109. package/src/router/model-binding.ts +0 -215
  110. package/src/router/optimized-route-matching.ts +0 -302
  111. package/src/router/route-building.ts +0 -221
  112. package/src/router/route-compiler.ts +0 -691
  113. package/src/router/route-matching.ts +0 -368
  114. package/src/router/route-trie.ts +0 -450
  115. package/src/router/router.ts +0 -1616
  116. package/src/router/server.ts +0 -684
  117. package/src/router/validation-integration.ts +0 -449
  118. package/src/router/view-rendering.ts +0 -233
  119. package/src/router/websocket.ts +0 -100
  120. package/src/routing/route-caching.ts +0 -402
  121. package/src/routing/route-throttling.ts +0 -469
  122. package/src/routing/subdomain-routing.ts +0 -492
  123. package/src/session/database-store.ts +0 -109
  124. package/src/session/file-store.ts +0 -148
  125. package/src/session/index.ts +0 -244
  126. package/src/session/memory-store.ts +0 -88
  127. package/src/session/redis-store.ts +0 -93
  128. package/src/streaming/index.ts +0 -17
  129. package/src/streaming/sse-handler.ts +0 -482
  130. package/src/streaming/stream-handler.ts +0 -552
  131. package/src/testing/auth-testing.ts +0 -448
  132. package/src/testing/file-upload-testing.ts +0 -543
  133. package/src/testing/index.ts +0 -10
  134. package/src/testing/middleware-testing.ts +0 -322
  135. package/src/testing/model-binding-testing.ts +0 -645
  136. package/src/testing/performance-testing.ts +0 -738
  137. package/src/testing/test-client.ts +0 -310
  138. package/src/testing/test-request.ts +0 -315
  139. package/src/testing/test-response.ts +0 -332
  140. package/src/testing/types.ts +0 -224
  141. package/src/testing/websocket-testing.ts +0 -590
  142. package/src/types/controller-types.ts +0 -385
  143. package/src/types/core.ts +0 -683
  144. package/src/types/middleware-types.ts +0 -422
  145. package/src/types/request-response-augmentation.ts +0 -489
  146. package/src/types/route-inference.ts +0 -372
  147. package/src/types.ts +0 -2123
  148. package/src/url.ts +0 -131
  149. package/src/utils/index.ts +0 -1
  150. package/src/utils/query-preservation.ts +0 -201
  151. package/src/utils.ts +0 -395
  152. package/src/validation/validator.ts +0 -688
  153. 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'