@stacksjs/bun-router 0.0.2

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 (131) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +397 -0
  3. package/bin/cli.ts +9 -0
  4. package/dist/auth.d.ts +77 -0
  5. package/dist/cache/lru-cache.d.ts +88 -0
  6. package/dist/cache/middleware-memoization.d.ts +101 -0
  7. package/dist/cache/route-cache-warmer.d.ts +125 -0
  8. package/dist/cache/sqlite-cache.d.ts +114 -0
  9. package/dist/cache/streaming-cache.d.ts +86 -0
  10. package/dist/chunk-r15a48wc.js +25448 -0
  11. package/dist/cli/colors.d.ts +12 -0
  12. package/dist/cli/index.d.ts +10 -0
  13. package/dist/cli/middleware.d.ts +31 -0
  14. package/dist/cli/openapi.d.ts +17 -0
  15. package/dist/cli/router.d.ts +15 -0
  16. package/dist/cli/routes.d.ts +30 -0
  17. package/dist/cli/utils.d.ts +68 -0
  18. package/dist/cli.d.ts +0 -0
  19. package/dist/cli.js +3195 -0
  20. package/dist/config.d.ts +274 -0
  21. package/dist/container/container.d.ts +141 -0
  22. package/dist/container/contextual-binding.d.ts +112 -0
  23. package/dist/container/decorators.d.ts +114 -0
  24. package/dist/container/service-provider.d.ts +221 -0
  25. package/dist/development/hot-reload.d.ts +129 -0
  26. package/dist/development/index.d.ts +144 -0
  27. package/dist/development/performance-profiler.d.ts +152 -0
  28. package/dist/development/route-debugger.d.ts +102 -0
  29. package/dist/development/route-inspector.d.ts +142 -0
  30. package/dist/development/typescript-utilities.d.ts +116 -0
  31. package/dist/docs.d.ts +10 -0
  32. package/dist/errors/circuit-breaker.d.ts +138 -0
  33. package/dist/errors/error-handler.d.ts +57 -0
  34. package/dist/errors/error-reporting.d.ts +135 -0
  35. package/dist/errors/exceptions.d.ts +178 -0
  36. package/dist/errors/graceful-degradation.d.ts +130 -0
  37. package/dist/errors/index.d.ts +6 -0
  38. package/dist/errors/router-errors.d.ts +97 -0
  39. package/dist/file-serving/static-files.d.ts +98 -0
  40. package/dist/index.d.ts +10 -0
  41. package/dist/index.js +13417 -0
  42. package/dist/middleware/auth.d.ts +34 -0
  43. package/dist/middleware/content_security_policy.d.ts +54 -0
  44. package/dist/middleware/cors.d.ts +5 -0
  45. package/dist/middleware/csrf.d.ts +7 -0
  46. package/dist/middleware/ddos_protection.d.ts +47 -0
  47. package/dist/middleware/file_security.d.ts +23 -0
  48. package/dist/middleware/file_upload.d.ts +41 -0
  49. package/dist/middleware/helmet.d.ts +54 -0
  50. package/dist/middleware/index.d.ts +55 -0
  51. package/dist/middleware/input_validation.d.ts +46 -0
  52. package/dist/middleware/json_body.d.ts +4 -0
  53. package/dist/middleware/performance_alerting.d.ts +88 -0
  54. package/dist/middleware/performance_dashboard.d.ts +97 -0
  55. package/dist/middleware/performance_monitor.d.ts +236 -0
  56. package/dist/middleware/pipeline.d.ts +90 -0
  57. package/dist/middleware/rate_limit.d.ts +33 -0
  58. package/dist/middleware/request_id.d.ts +4 -0
  59. package/dist/middleware/request_signing.d.ts +96 -0
  60. package/dist/middleware/request_tracer.d.ts +76 -0
  61. package/dist/middleware/response_cache.d.ts +90 -0
  62. package/dist/middleware/security.d.ts +70 -0
  63. package/dist/middleware/security_suite.d.ts +46 -0
  64. package/dist/middleware/session.d.ts +7 -0
  65. package/dist/model-binding/index.d.ts +17 -0
  66. package/dist/model-binding/model-middleware.d.ts +80 -0
  67. package/dist/model-binding/model-registry.d.ts +125 -0
  68. package/dist/model-binding.d.ts +123 -0
  69. package/dist/model-resolver-factory.d.ts +31 -0
  70. package/dist/observability/correlation.d.ts +131 -0
  71. package/dist/observability/health-checks.d.ts +129 -0
  72. package/dist/observability/index.d.ts +92 -0
  73. package/dist/observability/integration.d.ts +112 -0
  74. package/dist/observability/metrics.d.ts +135 -0
  75. package/dist/observability/tracing.d.ts +112 -0
  76. package/dist/optimization/bun-utilities.d.ts +106 -0
  77. package/dist/query-builder-integration.d.ts +24 -0
  78. package/dist/request/enhanced-request.d.ts +143 -0
  79. package/dist/request/macros.d.ts +267 -0
  80. package/dist/response/macros.d.ts +207 -0
  81. package/dist/response/response-factory.d.ts +93 -0
  82. package/dist/router/file-based-routing.d.ts +40 -0
  83. package/dist/router/file-streaming.d.ts +6 -0
  84. package/dist/router/fluent-router.d.ts +179 -0
  85. package/dist/router/fluent-routing.d.ts +198 -0
  86. package/dist/router/group-organization.d.ts +5 -0
  87. package/dist/router/handler-resolver.d.ts +13 -0
  88. package/dist/router/http-methods.d.ts +10 -0
  89. package/dist/router/index.d.ts +114 -0
  90. package/dist/router/middleware-integration.d.ts +86 -0
  91. package/dist/router/middleware.d.ts +5 -0
  92. package/dist/router/model-binding.d.ts +7 -0
  93. package/dist/router/optimized-route-matching.d.ts +6 -0
  94. package/dist/router/route-building.d.ts +5 -0
  95. package/dist/router/route-compiler.d.ts +67 -0
  96. package/dist/router/route-matching.d.ts +5 -0
  97. package/dist/router/route-trie.d.ts +69 -0
  98. package/dist/router/router.d.ts +133 -0
  99. package/dist/router/server.d.ts +5 -0
  100. package/dist/router/validation-integration.d.ts +116 -0
  101. package/dist/router/view-rendering.d.ts +5 -0
  102. package/dist/router/websocket.d.ts +5 -0
  103. package/dist/routing/route-caching.d.ts +105 -0
  104. package/dist/routing/route-throttling.d.ts +112 -0
  105. package/dist/routing/subdomain-routing.d.ts +159 -0
  106. package/dist/streaming/index.d.ts +15 -0
  107. package/dist/streaming/sse-handler.d.ts +81 -0
  108. package/dist/streaming/stream-handler.d.ts +81 -0
  109. package/dist/testing/auth-testing.d.ts +107 -0
  110. package/dist/testing/file-upload-testing.d.ts +139 -0
  111. package/dist/testing/index.d.ts +10 -0
  112. package/dist/testing/middleware-testing.d.ts +99 -0
  113. package/dist/testing/model-binding-testing.d.ts +132 -0
  114. package/dist/testing/performance-testing.d.ts +202 -0
  115. package/dist/testing/test-client.d.ts +58 -0
  116. package/dist/testing/test-request.d.ts +43 -0
  117. package/dist/testing/test-response.d.ts +45 -0
  118. package/dist/testing/types.d.ts +206 -0
  119. package/dist/testing/websocket-testing.d.ts +170 -0
  120. package/dist/types/controller-types.d.ts +303 -0
  121. package/dist/types/core.d.ts +526 -0
  122. package/dist/types/middleware-types.d.ts +315 -0
  123. package/dist/types/request-response-augmentation.d.ts +373 -0
  124. package/dist/types/route-inference.d.ts +287 -0
  125. package/dist/types.d.ts +1620 -0
  126. package/dist/utils/index.d.ts +1 -0
  127. package/dist/utils/query-preservation.d.ts +31 -0
  128. package/dist/utils.d.ts +69 -0
  129. package/dist/validation/validator.d.ts +169 -0
  130. package/dist/websocket/clustering.d.ts +114 -0
  131. package/package.json +81 -0
@@ -0,0 +1,274 @@
1
+ import type { RouterConfig } from './types';
2
+ export declare function getConfig(): Promise<RouterConfig>;
3
+ /**
4
+ * Default configuration for the router
5
+ */
6
+ export declare const defaultConfig: {
7
+ // General settings
8
+ verbose: false;
9
+ // Route paths
10
+ routesPath: 'routes';
11
+ apiRoutesPath: 'routes/api.ts';
12
+ webRoutesPath: 'routes/web.ts';
13
+ // URL prefixes
14
+ apiPrefix: '/api';
15
+ webPrefix: '';
16
+ // Default middleware configuration
17
+ defaultMiddleware: {
18
+ api: readonly ['security', 'helmet', 'cors', 'rate_limit', 'json_body', 'request_id'];
19
+ web: readonly ['security', 'helmet', 'ddos_protection', 'session', 'csrf']
20
+ };
21
+ // Documentation settings
22
+ docs: {
23
+ output: 'api-reference.md';
24
+ groupBy: 'path';
25
+ includeExamples: true;
26
+ title: 'API Reference';
27
+ description: 'API documentation for the application.';
28
+ version: '1.0.0';
29
+ baseUrl: 'http://localhost:3000';
30
+ contact: {
31
+ name: 'API Support';
32
+ email: 'support@example.com';
33
+ url: 'https://example.com/support'
34
+ };
35
+ security: {
36
+ bearer: {
37
+ type: 'http';
38
+ scheme: 'bearer';
39
+ bearerFormat: 'JWT'
40
+ }
41
+ }
42
+ };
43
+ // Server settings
44
+ server: {
45
+ port: 3000;
46
+ hostname: 'localhost';
47
+ development: unknown;
48
+ cors: {
49
+ enabled: true;
50
+ origin: '*';
51
+ methods: readonly ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
52
+ allowedHeaders: readonly ['Content-Type', 'Authorization'];
53
+ exposedHeaders: readonly ['X-Request-Id'];
54
+ credentials: false;
55
+ maxAge: 86400
56
+ };
57
+ rateLimit: {
58
+ enabled: true;
59
+ max: 100;
60
+ timeWindow: 60000;
61
+ // 1 minute
62
+ message: 'Too many requests, please try again later'
63
+ };
64
+ compression: {
65
+ enabled: true;
66
+ level: 6;
67
+ threshold: 1024
68
+ };
69
+ static: {
70
+ enabled: true;
71
+ dir: 'public';
72
+ maxAge: 86400
73
+ };
74
+ performance: {
75
+ cache: {
76
+ enabled: false;
77
+ type: 'memory';
78
+ ttl: 3600
79
+ };
80
+ prefetch: {
81
+ enabled: false;
82
+ paths: Array<never>;
83
+ maxConcurrent: 5
84
+ };
85
+ optimization: {
86
+ minify: false;
87
+ compress: false;
88
+ treeshake: false;
89
+ lazyLoad: false;
90
+ chunkSize: 50000
91
+ };
92
+ monitoring: {
93
+ enabled: false;
94
+ metrics: {
95
+ responseTime: true;
96
+ memoryUsage: true;
97
+ cpuUsage: true;
98
+ errorRate: true;
99
+ requestRate: true;
100
+ cacheStats: true
101
+ };
102
+ tracing: {
103
+ enabled: false;
104
+ sampleRate: 0.1;
105
+ // @ts-expect-error - Extended tracing config supports exporters array
106
+ exporters: readonly ['console'];
107
+ propagation: readonly ['w3c']
108
+ };
109
+ logging: {
110
+ level: 'info';
111
+ format: 'json';
112
+ destination: 'console'
113
+ }
114
+ }
115
+ };
116
+ security: {
117
+ schemes: {};
118
+ rateLimit: {
119
+ enabled: true;
120
+ max: 100;
121
+ timeWindow: 60000
122
+ };
123
+ cors: {
124
+ enabled: true;
125
+ origin: '*';
126
+ methods: readonly ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
127
+ };
128
+ csrf: {
129
+ enabled: true;
130
+ secret: 'csrf-secret';
131
+ cookie: {
132
+ name: 'csrf-token';
133
+ options: {
134
+ httpOnly: true;
135
+ secure: true;
136
+ sameSite: 'strict'
137
+ }
138
+ }
139
+ };
140
+ helmet: {
141
+ enabled: true;
142
+ contentSecurityPolicy: {
143
+ directives: {
144
+ 'default-src': readonly ['\'self\''];
145
+ 'script-src': readonly ['\'self\'', '\'unsafe-inline\''];
146
+ 'style-src': readonly ['\'self\'', '\'unsafe-inline\''];
147
+ 'img-src': readonly ['\'self\'', 'data:', 'https:'];
148
+ 'font-src': readonly ['\'self\''];
149
+ 'connect-src': readonly ['\'self\''];
150
+ 'media-src': readonly ['\'self\''];
151
+ 'object-src': readonly ['\'none\''];
152
+ 'child-src': readonly ['\'self\''];
153
+ 'worker-src': readonly ['\'self\''];
154
+ 'frame-ancestors': readonly ['\'none\''];
155
+ 'form-action': readonly ['\'self\''];
156
+ 'base-uri': readonly ['\'self\''];
157
+ 'manifest-src': readonly ['\'self\'']
158
+ }
159
+ };
160
+ xssFilter: true;
161
+ noSniff: true;
162
+ frameOptions: 'DENY';
163
+ hidePoweredBy: true;
164
+ hsts: {
165
+ maxAge: 31536000;
166
+ includeSubDomains: true;
167
+ preload: true
168
+ };
169
+ referrerPolicy: 'strict-origin-when-cross-origin'
170
+ };
171
+ ddos: {
172
+ enabled: true;
173
+ maxRequestsPerSecond: 10;
174
+ maxRequestsPerMinute: 100;
175
+ maxRequestsPerHour: 1000;
176
+ burstLimit: 20;
177
+ windowSize: 60000;
178
+ blockDuration: 300000;
179
+ whitelistedIPs: Array<never>;
180
+ blacklistedIPs: Array<never>;
181
+ trustProxy: true;
182
+ store: 'memory'
183
+ };
184
+ inputValidation: {
185
+ enabled: true;
186
+ sanitizeByDefault: true;
187
+ strictMode: false;
188
+ allowUnknownFields: true;
189
+ maxDepth: 10
190
+ };
191
+ attackPrevention: {
192
+ enabled: true;
193
+ sqlInjection: true;
194
+ xss: true;
195
+ pathTraversal: true;
196
+ commandInjection: true;
197
+ ldapInjection: true;
198
+ xxe: true;
199
+ customPatterns: Array<never>
200
+ };
201
+ requestFiltering: {
202
+ enabled: true;
203
+ blockSuspiciousPatterns: true;
204
+ maxRequestsPerMinute: 1000;
205
+ blockUserAgents: readonly ['sqlmap', 'nikto', 'nessus', 'openvas', 'nmap', 'masscan', 'zap', 'w3af'];
206
+ allowedMethods: readonly ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
207
+ requireUserAgent: false;
208
+ maxBodySize: 10485760;
209
+ // 10MB
210
+ maxUrlLength: 2048;
211
+ maxHeaderSize: 8192;
212
+ allowedContentTypes: readonly ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain', 'text/html', 'application/xml', 'text/xml']
213
+ };
214
+ ipFiltering: {
215
+ enabled: false;
216
+ whitelist: Array<never>;
217
+ blacklist: Array<never>;
218
+ blockPrivateIPs: false;
219
+ blockCloudProviders: false;
220
+ geoBlocking: {
221
+ enabled: false;
222
+ allowedCountries: Array<never>;
223
+ blockedCountries: Array<never>
224
+ }
225
+ };
226
+ responseSecurity: {
227
+ enabled: true;
228
+ removeServerHeaders: true;
229
+ addSecurityHeaders: true;
230
+ sanitizeErrors: true;
231
+ preventInfoDisclosure: true
232
+ };
233
+ auth: {
234
+ jwt: {
235
+ secret: 'jwt-secret';
236
+ expiresIn: '1h';
237
+ algorithm: 'HS256'
238
+ };
239
+ session: {
240
+ enabled: false;
241
+ secret: 'session-secret';
242
+ name: 'session';
243
+ resave: false;
244
+ rolling: true;
245
+ saveUninitialized: false;
246
+ cookie: {
247
+ maxAge: 86400000;
248
+ secure: true;
249
+ httpOnly: true;
250
+ sameSite: 'strict'
251
+ }
252
+ }
253
+ }
254
+ };
255
+ cluster: {
256
+ enabled: false;
257
+ workers: 'auto';
258
+ sticky: true
259
+ };
260
+ gracefulShutdown: {
261
+ enabled: true;
262
+ timeout: 30000;
263
+ signals: readonly ['SIGTERM', 'SIGINT'];
264
+ forceTimeout: 10000
265
+ };
266
+ middleware: {
267
+ order: Array<never>;
268
+ global: Array<never>
269
+ };
270
+ hooks: {}
271
+ }
272
+ };
273
+ // For backwards compatibility - synchronous access with default fallback
274
+ export declare const config: RouterConfig;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Get or create global container
3
+ */
4
+ export declare function getContainer(): Container;
5
+ /**
6
+ * Set global container
7
+ */
8
+ export declare function setContainer(container: Container): void;
9
+ /**
10
+ * Create new container
11
+ */
12
+ export declare function createContainer(options?: ContainerOptions): Container;
13
+ // Dependency injection decorators
14
+ export declare const INJECTABLE_METADATA_KEY: unique symbol;
15
+ export declare const INJECT_METADATA_KEY: unique symbol;
16
+ export declare const OPTIONAL_METADATA_KEY: unique symbol;
17
+ export declare const TAGGED_METADATA_KEY: unique symbol;
18
+ export declare interface BindingMetadata {
19
+ scope: BindingScope
20
+ tags?: string[]
21
+ when?: (context: ResolutionContext) => boolean
22
+ factory?: (...args: any[]) => any
23
+ dependencies?: Token[]
24
+ lazy?: boolean
25
+ decorators?: ((...args: any[]) => any)[]
26
+ }
27
+ export declare interface Binding<T = any> {
28
+ token: Token
29
+ implementation?: new (...args: any[]) => T
30
+ instance?: T
31
+ factory?: (...args: any[]) => T
32
+ value?: T
33
+ metadata: BindingMetadata
34
+ }
35
+ export declare interface ResolutionContext {
36
+ container: Container
37
+ token: Token
38
+ parent?: ResolutionContext
39
+ environment?: string
40
+ requestId?: string
41
+ depth: number
42
+ resolving: Set<Token>
43
+ }
44
+ export declare interface ContainerOptions {
45
+ autoRegister?: boolean
46
+ strictMode?: boolean
47
+ maxDepth?: number
48
+ enableDecorators?: boolean
49
+ enableInterception?: boolean
50
+ defaultScope?: BindingScope
51
+ }
52
+ // Decorator metadata
53
+ export declare interface InjectableMetadata {
54
+ token?: string | symbol
55
+ scope?: BindingScope
56
+ tags?: string[]
57
+ }
58
+ export declare interface InjectMetadata {
59
+ token: Token
60
+ optional?: boolean
61
+ tags?: string[]
62
+ when?: (context: ResolutionContext) => boolean
63
+ }
64
+ // Container binding types
65
+ export type BindingScope = 'singleton' | 'transient' | 'scoped' | 'request'
66
+ // Token can be a string, symbol, function, constructor, or generic Function
67
+ // eslint-disable-next-line ts/no-unsafe-function-type
68
+ export type Token = string | symbol | ((...args: any[]) => any) | (new (...args: any[]) => any) | Function
69
+ /**
70
+ * Main IoC Container implementation
71
+ */
72
+ export declare class Container {
73
+ private bindings: any;
74
+ private instances: any;
75
+ private scopedInstances: any;
76
+ private interceptors: any;
77
+ private parent?: Container;
78
+ private children: any;
79
+ private options: Required<ContainerOptions>;
80
+ constructor(options?: ContainerOptions);
81
+ bind<T>(token: Token): BindingBuilder<T>;
82
+ register<T>(binding: Binding<T>): this;
83
+ singleton<T>(token: Token, implementation: new (...args: any[]) => T): Container;
84
+ transient<T>(token: Token, implementation: new (...args: any[]) => T): Container;
85
+ value<T>(token: Token, value: T): Container;
86
+ factory<T>(token: Token, factory: (...args: any[]) => T): Container;
87
+ resolve<T>(token: Token, context?: Partial<ResolutionContext>): T;
88
+ resolveAll<T>(token: Token): T[];
89
+ resolveTagged<T>(tag: string): T[];
90
+ getTaggedBindings<T>(tag: string): Binding<T>[];
91
+ addInterceptor<T>(token: Token, interceptor: (service: T) => T): void;
92
+ registerController(controller: new (...args: any[]) => any): void;
93
+ getController<T>(controller: new (...args: any[]) => T): T;
94
+ isBound(token: Token): boolean;
95
+ unbind(token: Token): this;
96
+ createChild(options?: ContainerOptions): Container;
97
+ createScope(scopeId: string): Container;
98
+ getBindings(): Map<Token, Binding>;
99
+ clear(): this;
100
+ intercept<T>(token: string | symbol | ((...args: any[]) => any), interceptor: (instance: T, context: ResolutionContext) => T): this;
101
+ private resolveInternal<T>(token: Token, context: ResolutionContext): T;
102
+ protected createInstance<T>(binding: Binding<T>, context: ResolutionContext): T;
103
+ private createNewInstance<T>(binding: Binding<T>, context: ResolutionContext): T;
104
+ private createInstanceFromConstructor<T>(constructor: new (...args: any[]) => T, context: ResolutionContext): T;
105
+ private getConstructorDependencies(constructor: ((...args: any[]) => any) | (new (...args: any[]) => any)): Token[];
106
+ private parseConstructorDependencies(constructor: ((...args: any[]) => any) | (new (...args: any[]) => any)): string[];
107
+ private resolveDependencies(dependencies: Token[], context: ResolutionContext): any[];
108
+ private autoRegisterAndResolve<T>(constructor: new (...args: any[]) => T, context: ResolutionContext): T;
109
+ private applyDecorators(instance: any, constructor: ((...args: any[]) => any) | (new (...args: any[]) => any)): void;
110
+ private hasTag(binding: Binding, tag: string): boolean;
111
+ private tokenToString(token: Token): string;
112
+ private generateRequestId(): string;
113
+ }
114
+ /**
115
+ * Fluent binding builder
116
+ */
117
+ export declare class BindingBuilder<T> {
118
+ private binding: Partial<Binding<T>>;
119
+ private container: Container;
120
+ constructor(container: Container, token: Token);
121
+ to(implementation: new (...args: any[]) => T): this;
122
+ toValue(value: T): this;
123
+ toFactory(factory: (...args: any[]) => T): this;
124
+ toInstance(instance: T): this;
125
+ inSingletonScope(): this;
126
+ inTransientScope(): this;
127
+ inScopedScope(): this;
128
+ inRequestScope(): this;
129
+ withTags(tags: string[]): this;
130
+ when(condition: (context: ResolutionContext) => boolean): this;
131
+ lazy(): this;
132
+ build(): Container;
133
+ }
134
+ // Extend Reflect with metadata methods
135
+ declare namespace global {
136
+ namespace Reflect {
137
+ function getMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): any;
138
+ function defineMetadata(metadataKey: any, metadataValue: any, target: any, propertyKey?: string | symbol): void;
139
+ }
140
+ }
141
+ export { Container as DIContainer };
@@ -0,0 +1,112 @@
1
+ import { Container } from './container';
2
+ import type { Binding, ResolutionContext, Token } from './container';
3
+ // Contextual binding interfaces
4
+ export declare interface ContextualBinding<T = any> extends Binding<T> {
5
+ conditions: BindingCondition[]
6
+ priority: number
7
+ fallback?: Binding<T>
8
+ }
9
+ export declare interface BindingCondition {
10
+ type: 'environment' | 'custom' | 'tag' | 'parent' | 'request'
11
+ predicate: (context: ResolutionContext) => boolean
12
+ description?: string
13
+ }
14
+ export declare interface EnvironmentConfig {
15
+ name: string
16
+ variables: Record<string, any>
17
+ services: Record<string, any>
18
+ features: string[]
19
+ }
20
+ export declare interface ContextualBindingBuilder<T> {
21
+ to: (implementation: new (...args: any[]) => T) => ContextualBindingBuilder<T>
22
+ toValue: (value: T) => ContextualBindingBuilder<T>
23
+ toFactory: (factory: (...args: any[]) => T) => ContextualBindingBuilder<T>
24
+ when: (condition: BindingCondition) => ContextualBindingBuilder<T>
25
+ whenEnvironment: (...environments: string[]) => ContextualBindingBuilder<T>
26
+ whenTag: (tag: string) => ContextualBindingBuilder<T>
27
+ whenParent: (parentToken: string | symbol | ((...args: any[]) => any)) => ContextualBindingBuilder<T>
28
+ whenRequest: (predicate: (context: ResolutionContext) => boolean) => ContextualBindingBuilder<T>
29
+ withPriority: (priority: number) => ContextualBindingBuilder<T>
30
+ withFallback: (fallback: Binding<T>) => ContextualBindingBuilder<T>
31
+ build: () => Container
32
+ }
33
+ /**
34
+ * Environment manager for handling different deployment contexts
35
+ */
36
+ export declare class EnvironmentManager {
37
+ private environments: any;
38
+ private currentEnvironment: string;
39
+ private variables: any;
40
+ constructor(defaultEnvironment?: string);
41
+ register(config: EnvironmentConfig): this;
42
+ setEnvironment(name: string): this;
43
+ getCurrentEnvironment(): string;
44
+ getEnvironment(name?: string): EnvironmentConfig | undefined;
45
+ is(environments: string[]): boolean;
46
+ get(key: string, defaultValue?: any): any;
47
+ set(key: string, value: any): this;
48
+ hasFeature(feature: string): boolean;
49
+ private loadEnvironmentVariables(): void;
50
+ }
51
+ /**
52
+ * Contextual binding builder implementation
53
+ */
54
+ export declare class DefaultContextualBindingBuilder<T> implements ContextualBindingBuilder<T> {
55
+ private binding: Partial<ContextualBinding<T>>;
56
+ private container: ContextualContainer;
57
+ constructor(container: ContextualContainer, token: Token);
58
+ when(condition: BindingCondition): ContextualBindingBuilder<T>;
59
+ whenEnvironment(environments: string[]): ContextualBindingBuilder<T>;
60
+ whenTag(tag: string): ContextualBindingBuilder<T>;
61
+ whenParent(parentToken: string | symbol | ((...args: any[]) => any)): ContextualBindingBuilder<T>;
62
+ whenRequest(predicate: (context: ResolutionContext) => boolean): ContextualBindingBuilder<T>;
63
+ withPriority(priority: number): ContextualBindingBuilder<T>;
64
+ withFallback(fallback: Binding<T>): ContextualBindingBuilder<T>;
65
+ to(implementation: new (...args: any[]) => T): this;
66
+ toValue(value: T): this;
67
+ toFactory(factory: (...args: any[]) => T): this;
68
+ inSingletonScope(): this;
69
+ inTransientScope(): this;
70
+ build(): Container;
71
+ }
72
+ /**
73
+ * Enhanced container with contextual binding support
74
+ */
75
+ export declare class ContextualContainer extends Container {
76
+ private contextualBindings: any;
77
+ private environmentManager: EnvironmentManager;
78
+ constructor(options?: any);
79
+ bindContextual<T>(token: Token): ContextualBindingBuilder<T>;
80
+ registerContextualBinding<T>(binding: ContextualBinding<T>): this;
81
+ getEnvironmentManager(): EnvironmentManager;
82
+ forDevelopment<T>(token: Token): ContextualBindingBuilder<T>;
83
+ forProduction<T>(token: Token): ContextualBindingBuilder<T>;
84
+ forTesting<T>(token: Token): ContextualBindingBuilder<T>;
85
+ forStaging<T>(token: Token): ContextualBindingBuilder<T>;
86
+ resolve<T>(token: Token, context?: Partial<ResolutionContext>): T;
87
+ private findContextualBinding(token: Token, context: ResolutionContext): ContextualBinding | undefined;
88
+ private evaluateConditions(conditions: BindingCondition[], context: ResolutionContext): boolean;
89
+ private createInstanceFromContextualBinding<T>(binding: ContextualBinding<T>, context: ResolutionContext): T;
90
+ private generateContextualRequestId(): string;
91
+ }
92
+ /**
93
+ * Pre-configured environment setups
94
+ */
95
+ export declare class EnvironmentPresets {
96
+ static development(): EnvironmentConfig;
97
+ static production(): EnvironmentConfig;
98
+ static testing(): EnvironmentConfig;
99
+ static staging(): EnvironmentConfig;
100
+ }
101
+ /**
102
+ * Contextual binding conditions factory
103
+ */
104
+ export declare class BindingConditions {
105
+ static environment(environments: string[]): BindingCondition;
106
+ static feature(featureName: string): BindingCondition;
107
+ static envVar(key: string, value: any): BindingCondition;
108
+ static requestPattern(pattern: RegExp): BindingCondition;
109
+ static timeRange(startHour: number, endHour: number): BindingCondition;
110
+ static custom(predicate: (context: ResolutionContext) => boolean, description?: string): BindingCondition;
111
+ }
112
+ export { ContextualContainer as DIContainer };
@@ -0,0 +1,114 @@
1
+ import { Container } from './container';
2
+ import type { ResolutionContext } from './container';
3
+ /**
4
+ * Injectable decorator - marks a class as injectable
5
+ */
6
+ export declare function Injectable(metadata?: InjectableMetadata): ClassDecorator;
7
+ /**
8
+ * Inject decorator - specifies dependency injection for constructor parameters
9
+ */
10
+ export declare function Inject(token: string | symbol | Function, options?: {
11
+ optional?: boolean
12
+ tags?: string[]
13
+ when?: (context: ResolutionContext) => boolean
14
+ }): ParameterDecorator;
15
+ /**
16
+ * Optional decorator - marks a dependency as optional
17
+ */
18
+ export declare function Optional(): ParameterDecorator;
19
+ /**
20
+ * Tagged decorator - injects services with specific tags
21
+ */
22
+ export declare function Tagged(tag: string): ParameterDecorator;
23
+ /**
24
+ * Controller decorator - marks a class as a controller
25
+ */
26
+ export declare function Controller(prefix?: string, options?: {
27
+ middleware?: Function[]
28
+ tags?: string[]
29
+ }): ClassDecorator;
30
+ /**
31
+ * HTTP method decorators
32
+ */
33
+ export declare function Get(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
34
+ export declare function Post(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
35
+ export declare function Put(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
36
+ export declare function Delete(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
37
+ export declare function Patch(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
38
+ export declare function Options(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
39
+ export declare function Head(path?: string, options?: { middleware?: Function[], tags?: string[] }): MethodDecorator;
40
+ /**
41
+ * UseMiddleware decorator - applies middleware to a class or method
42
+ */
43
+ export declare function UseMiddleware(...middleware: Function[]): ClassDecorator & MethodDecorator;
44
+ /**
45
+ * Parameter decorators for route handlers
46
+ */
47
+ export declare function Param(key?: string): ParameterDecorator;
48
+ export declare function Query(key?: string): ParameterDecorator;
49
+ export declare function Body(): ParameterDecorator;
50
+ export declare function Header(key?: string): ParameterDecorator;
51
+ export declare function Cookie(key?: string): ParameterDecorator;
52
+ export declare function InjectParam(token: string | symbol | Function): ParameterDecorator;
53
+ // Metadata keys with explicit types
54
+ export declare const INJECTABLE_METADATA_KEY: unique symbol;
55
+ export declare const INJECT_METADATA_KEY: unique symbol;
56
+ export declare const OPTIONAL_METADATA_KEY: unique symbol;
57
+ export declare const TAGGED_METADATA_KEY: unique symbol;
58
+ export declare const CONTROLLER_METADATA_KEY: unique symbol;
59
+ export declare const ROUTE_METADATA_KEY: unique symbol;
60
+ export declare const MIDDLEWARE_METADATA_KEY: unique symbol;
61
+ export declare const PARAM_METADATA_KEY: unique symbol;
62
+ // Export a default instance
63
+ export declare const decoratorContainer: DecoratorContainer;
64
+ // Decorator metadata interfaces
65
+ export declare interface InjectableMetadata {
66
+ token?: string | symbol
67
+ scope?: 'singleton' | 'transient' | 'scoped' | 'request'
68
+ tags?: string[]
69
+ }
70
+ export declare interface InjectMetadata {
71
+ token: string | symbol | Function
72
+ optional?: boolean
73
+ tags?: string[]
74
+ when?: (context: ResolutionContext) => boolean
75
+ }
76
+ export declare interface ControllerMetadata {
77
+ prefix?: string
78
+ middleware?: Function[]
79
+ tags?: string[]
80
+ }
81
+ export declare interface RouteMetadata {
82
+ method: string
83
+ path: string
84
+ middleware?: Function[]
85
+ tags?: string[]
86
+ }
87
+ export declare interface ParamMetadata {
88
+ type: 'param' | 'query' | 'body' | 'header' | 'cookie'
89
+ key?: string
90
+ token?: string | symbol | Function
91
+ optional?: boolean
92
+ transform?: (value: any) => any
93
+ validate?: (value: any) => boolean
94
+ }
95
+ /**
96
+ * Metadata reader utility class
97
+ */
98
+ export declare class MetadataReader {
99
+ static getInjectableMetadata(target: Function): InjectableMetadata | undefined;
100
+ static getInjectMetadata(target: Function): InjectMetadata[];
101
+ static getOptionalMetadata(target: Function): boolean[];
102
+ static getTaggedMetadata(target: Function): string[];
103
+ static getControllerMetadata(target: Function): ControllerMetadata | undefined;
104
+ static getAllRoutes(target: Function): any[];
105
+ static getMiddlewareMetadata(target: Function, propertyKey?: string | symbol): Function[];
106
+ static getParamMetadata(target: Function, propertyKey: string | symbol): ParamMetadata[];
107
+ }
108
+ /**
109
+ * Modern Decorator Container
110
+ */
111
+ export declare class DecoratorContainer extends Container {
112
+ registerController(controllerClass: Function): void;
113
+ resolve<T>(token: string | symbol | Function, context?: ResolutionContext): T;
114
+ }