@stacksjs/bun-router 0.0.4 → 0.0.6

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 (272) hide show
  1. package/README.md +2 -2
  2. package/dist/auth.d.ts +134 -0
  3. package/dist/cache/lru-cache.d.ts +139 -0
  4. package/dist/cache/middleware-memoization.d.ts +151 -0
  5. package/dist/cache/route-cache-warmer.d.ts +161 -0
  6. package/dist/cache/sqlite-cache.d.ts +209 -0
  7. package/dist/cache/streaming-cache.d.ts +132 -0
  8. package/dist/chunk-jhsk5c5b.js +15758 -0
  9. package/dist/cli/colors.d.ts +15 -0
  10. package/dist/cli/index.d.ts +10 -0
  11. package/dist/cli/middleware.d.ts +31 -0
  12. package/dist/cli/openapi.d.ts +17 -0
  13. package/dist/cli/router.d.ts +15 -0
  14. package/dist/cli/routes.d.ts +29 -0
  15. package/dist/cli/utils.d.ts +74 -0
  16. package/dist/cli.d.ts +1 -1
  17. package/dist/cli.js +2 -2
  18. package/dist/config.d.ts +7 -0
  19. package/dist/container/container.d.ts +273 -0
  20. package/dist/container/contextual-binding.d.ts +240 -0
  21. package/dist/container/decorators.d.ts +141 -0
  22. package/dist/container/service-provider.d.ts +285 -0
  23. package/dist/development/hot-reload.d.ts +187 -0
  24. package/dist/development/index.d.ts +167 -0
  25. package/dist/development/performance-profiler.d.ts +217 -0
  26. package/dist/development/route-debugger.d.ts +154 -0
  27. package/dist/development/route-inspector.d.ts +211 -0
  28. package/dist/development/typescript-utilities.d.ts +209 -0
  29. package/dist/docs.d.ts +11 -0
  30. package/dist/errors/circuit-breaker.d.ts +195 -0
  31. package/dist/errors/error-handler.d.ts +88 -0
  32. package/dist/errors/error-reporting.d.ts +144 -0
  33. package/dist/errors/exceptions.d.ts +184 -0
  34. package/dist/errors/graceful-degradation.d.ts +154 -0
  35. package/dist/errors/index.d.ts +9 -0
  36. package/dist/errors/router-errors.d.ts +110 -0
  37. package/dist/file-serving/static-files.d.ts +143 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +320 -206
  40. package/dist/middleware/auth.d.ts +63 -0
  41. package/dist/middleware/content_security_policy.d.ts +53 -0
  42. package/dist/middleware/cors.d.ts +5 -0
  43. package/dist/middleware/csrf.d.ts +7 -0
  44. package/dist/middleware/ddos_protection.d.ts +39 -0
  45. package/dist/middleware/file_security.d.ts +26 -0
  46. package/dist/middleware/file_upload.d.ts +38 -0
  47. package/dist/middleware/helmet.d.ts +54 -0
  48. package/dist/middleware/index.d.ts +44 -0
  49. package/dist/middleware/input_validation.d.ts +45 -0
  50. package/dist/middleware/json_body.d.ts +4 -0
  51. package/dist/middleware/performance_alerting.d.ts +87 -0
  52. package/dist/middleware/performance_dashboard.d.ts +87 -0
  53. package/dist/middleware/performance_monitor.d.ts +209 -0
  54. package/dist/middleware/pipeline.d.ts +131 -0
  55. package/dist/middleware/rate_limit.d.ts +36 -0
  56. package/dist/middleware/request_id.d.ts +4 -0
  57. package/dist/middleware/request_signing.d.ts +153 -0
  58. package/dist/middleware/request_tracer.d.ts +72 -0
  59. package/dist/middleware/response_cache.d.ts +97 -0
  60. package/dist/middleware/security.d.ts +69 -0
  61. package/dist/middleware/security_suite.d.ts +46 -0
  62. package/dist/middleware/session.d.ts +23 -0
  63. package/dist/model-binding/index.d.ts +2 -0
  64. package/dist/model-binding/model-middleware.d.ts +118 -0
  65. package/dist/model-binding/model-registry.d.ts +164 -0
  66. package/dist/model-binding.d.ts +185 -0
  67. package/dist/model-resolver-factory.d.ts +31 -0
  68. package/dist/observability/correlation.d.ts +187 -0
  69. package/dist/observability/health-checks.d.ts +186 -0
  70. package/dist/observability/index.d.ts +60 -0
  71. package/dist/observability/integration.d.ts +147 -0
  72. package/dist/observability/metrics.d.ts +184 -0
  73. package/dist/observability/tracing.d.ts +187 -0
  74. package/dist/optimization/bun-utilities.d.ts +224 -0
  75. package/dist/query-builder-integration.d.ts +36 -0
  76. package/dist/request/context.d.ts +34 -0
  77. package/dist/request/enhanced-request.d.ts +213 -0
  78. package/dist/request/macros.d.ts +300 -0
  79. package/dist/response/macros.d.ts +245 -0
  80. package/dist/response/response-factory.d.ts +133 -0
  81. package/dist/router/api-routes.d.ts +5 -0
  82. package/dist/router/file-based-routing.d.ts +118 -0
  83. package/dist/router/file-streaming.d.ts +5 -0
  84. package/dist/router/fluent-router.d.ts +315 -0
  85. package/dist/router/fluent-routing.d.ts +271 -0
  86. package/dist/router/group-organization.d.ts +5 -0
  87. package/dist/router/handler-resolver.d.ts +24 -0
  88. package/dist/router/http-methods.d.ts +10 -0
  89. package/dist/router/index.d.ts +113 -0
  90. package/dist/router/middleware-groups.d.ts +94 -0
  91. package/dist/router/middleware-integration.d.ts +112 -0
  92. package/dist/router/middleware.d.ts +5 -0
  93. package/dist/router/model-binding.d.ts +5 -0
  94. package/dist/router/optimized-route-matching.d.ts +6 -0
  95. package/dist/router/route-building.d.ts +5 -0
  96. package/dist/router/route-compiler.d.ts +153 -0
  97. package/dist/router/route-matching.d.ts +5 -0
  98. package/dist/router/route-trie.d.ts +114 -0
  99. package/dist/router/router.d.ts +276 -0
  100. package/dist/router/server.d.ts +5 -0
  101. package/dist/router/validation-integration.d.ts +170 -0
  102. package/dist/router/view-rendering.d.ts +5 -0
  103. package/dist/router/websocket.d.ts +5 -0
  104. package/dist/routing/route-caching.d.ts +129 -0
  105. package/dist/routing/route-throttling.d.ts +150 -0
  106. package/dist/routing/subdomain-routing.d.ts +206 -0
  107. package/dist/session/database-store.d.ts +51 -0
  108. package/dist/session/file-store.d.ts +22 -0
  109. package/dist/session/index.d.ts +106 -0
  110. package/dist/session/memory-store.d.ts +21 -0
  111. package/dist/session/redis-store.d.ts +31 -0
  112. package/dist/streaming/index.d.ts +3 -0
  113. package/dist/streaming/sse-handler.d.ts +138 -0
  114. package/dist/streaming/stream-handler.d.ts +114 -0
  115. package/dist/testing/auth-testing.d.ts +156 -0
  116. package/dist/testing/file-upload-testing.d.ts +190 -0
  117. package/dist/testing/index.d.ts +10 -0
  118. package/dist/testing/middleware-testing.d.ts +138 -0
  119. package/dist/testing/model-binding-testing.d.ts +186 -0
  120. package/dist/testing/performance-testing.d.ts +235 -0
  121. package/dist/testing/test-client.d.ts +117 -0
  122. package/dist/testing/test-request.d.ts +85 -0
  123. package/dist/testing/test-response.d.ts +90 -0
  124. package/dist/testing/types.d.ts +207 -0
  125. package/dist/testing/websocket-testing.d.ts +227 -0
  126. package/dist/types/controller-types.d.ts +208 -0
  127. package/dist/types/core.d.ts +543 -0
  128. package/dist/types/middleware-types.d.ts +227 -0
  129. package/dist/types/request-response-augmentation.d.ts +261 -0
  130. package/dist/types/route-inference.d.ts +168 -0
  131. package/dist/types.d.ts +1776 -0
  132. package/dist/url.d.ts +56 -0
  133. package/dist/utils/index.d.ts +1 -0
  134. package/dist/utils/query-preservation.d.ts +48 -0
  135. package/dist/utils.d.ts +69 -0
  136. package/dist/validation/validator.d.ts +140 -0
  137. package/dist/websocket/clustering.d.ts +185 -0
  138. package/package.json +18 -4
  139. package/src/auth.ts +469 -0
  140. package/src/cache/lru-cache.ts +457 -0
  141. package/src/cache/middleware-memoization.ts +531 -0
  142. package/src/cache/route-cache-warmer.ts +486 -0
  143. package/src/cache/sqlite-cache.ts +783 -0
  144. package/src/cache/streaming-cache.ts +572 -0
  145. package/src/cli/colors.ts +29 -0
  146. package/src/cli/index.ts +287 -0
  147. package/src/cli/middleware.ts +291 -0
  148. package/src/cli/openapi.ts +407 -0
  149. package/src/cli/router.ts +188 -0
  150. package/src/cli/routes.ts +265 -0
  151. package/src/cli/utils.ts +531 -0
  152. package/src/cli.ts +5 -0
  153. package/src/config.ts +322 -0
  154. package/src/container/container.ts +740 -0
  155. package/src/container/contextual-binding.ts +603 -0
  156. package/src/container/decorators.ts +359 -0
  157. package/src/container/service-provider.ts +596 -0
  158. package/src/development/hot-reload.ts +673 -0
  159. package/src/development/index.ts +499 -0
  160. package/src/development/performance-profiler.ts +717 -0
  161. package/src/development/route-debugger.ts +527 -0
  162. package/src/development/route-inspector.ts +749 -0
  163. package/src/development/typescript-utilities.ts +678 -0
  164. package/src/docs.ts +397 -0
  165. package/src/errors/circuit-breaker.ts +732 -0
  166. package/src/errors/error-handler.ts +569 -0
  167. package/src/errors/error-reporting.ts +672 -0
  168. package/src/errors/exceptions.ts +536 -0
  169. package/src/errors/graceful-degradation.ts +621 -0
  170. package/src/errors/index.ts +21 -0
  171. package/src/errors/router-errors.ts +632 -0
  172. package/src/file-serving/static-files.ts +581 -0
  173. package/src/index.ts +14 -0
  174. package/src/middleware/auth.ts +219 -0
  175. package/src/middleware/content_security_policy.ts +215 -0
  176. package/src/middleware/cors.ts +74 -0
  177. package/src/middleware/csrf.ts +108 -0
  178. package/src/middleware/ddos_protection.ts +255 -0
  179. package/src/middleware/file_security.ts +191 -0
  180. package/src/middleware/file_upload.ts +264 -0
  181. package/src/middleware/helmet.ts +268 -0
  182. package/src/middleware/index.ts +117 -0
  183. package/src/middleware/input_validation.ts +449 -0
  184. package/src/middleware/json_body.ts +37 -0
  185. package/src/middleware/performance_alerting.ts +538 -0
  186. package/src/middleware/performance_dashboard.ts +661 -0
  187. package/src/middleware/performance_monitor.ts +943 -0
  188. package/src/middleware/pipeline.ts +489 -0
  189. package/src/middleware/rate_limit.ts +245 -0
  190. package/src/middleware/request_id.ts +36 -0
  191. package/src/middleware/request_signing.ts +636 -0
  192. package/src/middleware/request_tracer.ts +636 -0
  193. package/src/middleware/response_cache.ts +743 -0
  194. package/src/middleware/security.ts +482 -0
  195. package/src/middleware/security_suite.ts +257 -0
  196. package/src/middleware/session.ts +91 -0
  197. package/src/model-binding/index.ts +18 -0
  198. package/src/model-binding/model-middleware.ts +425 -0
  199. package/src/model-binding/model-registry.ts +550 -0
  200. package/src/model-binding.ts +370 -0
  201. package/src/model-resolver-factory.ts +106 -0
  202. package/src/observability/correlation.ts +691 -0
  203. package/src/observability/health-checks.ts +729 -0
  204. package/src/observability/index.ts +184 -0
  205. package/src/observability/integration.ts +548 -0
  206. package/src/observability/metrics.ts +753 -0
  207. package/src/observability/tracing.ts +638 -0
  208. package/src/optimization/bun-utilities.ts +778 -0
  209. package/src/query-builder-integration.ts +137 -0
  210. package/src/request/context.ts +62 -0
  211. package/src/request/enhanced-request.ts +857 -0
  212. package/src/request/macros.ts +688 -0
  213. package/src/response/macros.ts +612 -0
  214. package/src/response/response-factory.ts +588 -0
  215. package/src/router/api-routes.ts +243 -0
  216. package/src/router/file-based-routing.ts +670 -0
  217. package/src/router/file-streaming.ts +372 -0
  218. package/src/router/fluent-router.ts +927 -0
  219. package/src/router/fluent-routing.ts +797 -0
  220. package/src/router/group-organization.ts +213 -0
  221. package/src/router/handler-resolver.ts +291 -0
  222. package/src/router/http-methods.ts +377 -0
  223. package/src/router/index.ts +185 -0
  224. package/src/router/middleware-groups.ts +222 -0
  225. package/src/router/middleware-integration.ts +399 -0
  226. package/src/router/middleware.ts +231 -0
  227. package/src/router/model-binding.ts +215 -0
  228. package/src/router/optimized-route-matching.ts +253 -0
  229. package/src/router/route-building.ts +212 -0
  230. package/src/router/route-compiler.ts +702 -0
  231. package/src/router/route-matching.ts +349 -0
  232. package/src/router/route-trie.ts +464 -0
  233. package/src/router/router.ts +1508 -0
  234. package/src/router/server.ts +406 -0
  235. package/src/router/validation-integration.ts +443 -0
  236. package/src/router/view-rendering.ts +233 -0
  237. package/src/router/websocket.ts +100 -0
  238. package/src/routing/route-caching.ts +402 -0
  239. package/src/routing/route-throttling.ts +469 -0
  240. package/src/routing/subdomain-routing.ts +492 -0
  241. package/src/session/database-store.ts +109 -0
  242. package/src/session/file-store.ts +148 -0
  243. package/src/session/index.ts +244 -0
  244. package/src/session/memory-store.ts +88 -0
  245. package/src/session/redis-store.ts +93 -0
  246. package/src/streaming/index.ts +17 -0
  247. package/src/streaming/sse-handler.ts +482 -0
  248. package/src/streaming/stream-handler.ts +552 -0
  249. package/src/testing/auth-testing.ts +446 -0
  250. package/src/testing/file-upload-testing.ts +543 -0
  251. package/src/testing/index.ts +10 -0
  252. package/src/testing/middleware-testing.ts +322 -0
  253. package/src/testing/model-binding-testing.ts +645 -0
  254. package/src/testing/performance-testing.ts +738 -0
  255. package/src/testing/test-client.ts +310 -0
  256. package/src/testing/test-request.ts +315 -0
  257. package/src/testing/test-response.ts +332 -0
  258. package/src/testing/types.ts +224 -0
  259. package/src/testing/websocket-testing.ts +590 -0
  260. package/src/types/controller-types.ts +385 -0
  261. package/src/types/core.ts +683 -0
  262. package/src/types/middleware-types.ts +419 -0
  263. package/src/types/request-response-augmentation.ts +489 -0
  264. package/src/types/route-inference.ts +357 -0
  265. package/src/types.ts +2049 -0
  266. package/src/url.ts +126 -0
  267. package/src/utils/index.ts +1 -0
  268. package/src/utils/query-preservation.ts +201 -0
  269. package/src/utils.ts +327 -0
  270. package/src/validation/validator.ts +685 -0
  271. package/src/websocket/clustering.ts +762 -0
  272. package/dist/chunk-cjdekj87.js +0 -25886
@@ -0,0 +1,359 @@
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()