@kuckit/infrastructure 1.0.1 → 1.0.3

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 (132) hide show
  1. package/dist/apply-decorators-CW23qWy7.d.ts +23 -0
  2. package/dist/apply-decorators-CaHIAL5X.js +29 -0
  3. package/dist/apply-decorators-CaHIAL5X.js.map +1 -0
  4. package/dist/cache/in-memory-cache-store.d.ts +2 -0
  5. package/dist/cache/in-memory-cache-store.js +3 -0
  6. package/dist/cache/index.d.ts +3 -0
  7. package/dist/cache/index.js +4 -0
  8. package/dist/cache-BjdZ-Ye4.js +1 -0
  9. package/dist/core.module-B1TdC0yX.d.ts +17 -0
  10. package/dist/core.module-DMtIkTcz.js +48 -0
  11. package/dist/core.module-DMtIkTcz.js.map +1 -0
  12. package/dist/db/drizzle/db.d.ts +2 -0
  13. package/dist/db/drizzle/db.js +3 -0
  14. package/dist/db/drizzle/repositories/index.d.ts +3 -0
  15. package/dist/db/drizzle/repositories/index.js +4 -0
  16. package/dist/db/drizzle/repositories/user.drizzle.d.ts +2 -0
  17. package/dist/db/drizzle/repositories/user.drizzle.js +3 -0
  18. package/dist/db/transaction.d.ts +2 -0
  19. package/dist/db/transaction.js +4 -0
  20. package/dist/db-C4IcCT04.js +25 -0
  21. package/dist/db-C4IcCT04.js.map +1 -0
  22. package/dist/db-tAPHBDyL.d.ts +17 -0
  23. package/dist/decorators/apply-decorators.d.ts +2 -0
  24. package/dist/decorators/apply-decorators.js +5 -0
  25. package/dist/decorators/index.d.ts +8 -0
  26. package/dist/decorators/index.js +9 -0
  27. package/dist/decorators/use-case-decorator.d.ts +3 -0
  28. package/dist/decorators/use-case-decorator.js +4 -0
  29. package/dist/decorators/with-caching.d.ts +2 -0
  30. package/dist/decorators/with-caching.js +3 -0
  31. package/dist/decorators/with-rate-limit.d.ts +2 -0
  32. package/dist/decorators/with-rate-limit.js +3 -0
  33. package/dist/decorators/with-retry.d.ts +2 -0
  34. package/dist/decorators/with-retry.js +3 -0
  35. package/dist/decorators-CqyPE9AQ.js +1 -0
  36. package/dist/error-handler-BDid7SIZ.d.ts +47 -0
  37. package/dist/error-handler-D4s_TTI1.js +80 -0
  38. package/dist/error-handler-D4s_TTI1.js.map +1 -0
  39. package/dist/errors/error-handler.d.ts +3 -0
  40. package/dist/errors/error-handler.js +4 -0
  41. package/dist/errors/index.d.ts +4 -0
  42. package/dist/errors/index.js +5 -0
  43. package/dist/errors-BB_jeye8.js +43 -0
  44. package/dist/errors-BB_jeye8.js.map +1 -0
  45. package/dist/errors-DfkerzdO.js +1 -0
  46. package/dist/event-publisher-adapter-B02oKEmP.js +46 -0
  47. package/dist/event-publisher-adapter-B02oKEmP.js.map +1 -0
  48. package/dist/event-publisher-adapter-CpxK0OJ3.d.ts +12 -0
  49. package/dist/events/event-publisher-adapter.d.ts +2 -0
  50. package/dist/events/event-publisher-adapter.js +3 -0
  51. package/dist/events/in-memory-event-bus.d.ts +2 -0
  52. package/dist/events/in-memory-event-bus.js +3 -0
  53. package/dist/events/in-memory-event-publisher.d.ts +2 -0
  54. package/dist/events/in-memory-event-publisher.js +3 -0
  55. package/dist/events/index.d.ts +5 -0
  56. package/dist/events/index.js +6 -0
  57. package/dist/events-Dqynhuj2.js +1 -0
  58. package/dist/in-memory-cache-store-BaRxM--K.d.ts +31 -0
  59. package/dist/in-memory-cache-store-oClww-8m.js +72 -0
  60. package/dist/in-memory-cache-store-oClww-8m.js.map +1 -0
  61. package/dist/in-memory-event-bus-BCyPrNAE.js +60 -0
  62. package/dist/in-memory-event-bus-BCyPrNAE.js.map +1 -0
  63. package/dist/in-memory-event-bus-CqIBLRze.d.ts +21 -0
  64. package/dist/in-memory-event-publisher-BdOlxfkx.js +28 -0
  65. package/dist/in-memory-event-publisher-BdOlxfkx.js.map +1 -0
  66. package/dist/in-memory-event-publisher-CxOQ-hnq.d.ts +12 -0
  67. package/dist/in-memory-rate-limiter-BDSHZXxf.js +72 -0
  68. package/dist/in-memory-rate-limiter-BDSHZXxf.js.map +1 -0
  69. package/dist/in-memory-rate-limiter-DJsxdZZR.d.ts +34 -0
  70. package/dist/index-B5F3AfVc.d.ts +1 -0
  71. package/dist/index-B7z6dpFd.d.ts +1 -0
  72. package/dist/index-BH67NKRs.d.ts +2 -0
  73. package/dist/index-C0yeuOwC.d.ts +1 -0
  74. package/dist/index-C6nYd7xV.d.ts +2 -0
  75. package/dist/index-DVGDAddE.d.ts +1 -0
  76. package/dist/index-DXJbbtWQ.d.ts +1 -0
  77. package/dist/index-LKrIp3Oo.d.ts +1 -0
  78. package/dist/index.d.ts +29 -506
  79. package/dist/index.js +27 -969
  80. package/dist/logger-Bl10drB8.d.ts +23 -0
  81. package/dist/logging/index.d.ts +5 -0
  82. package/dist/logging/index.js +5 -0
  83. package/dist/logging/request-logger.d.ts +2 -0
  84. package/dist/logging/request-logger.js +3 -0
  85. package/dist/logging/structured-logger.d.ts +3 -0
  86. package/dist/logging/structured-logger.js +3 -0
  87. package/dist/logging-4mLSrMc6.js +1 -0
  88. package/dist/modules/core.module.d.ts +10 -0
  89. package/dist/modules/core.module.js +13 -0
  90. package/dist/modules/index.d.ts +12 -0
  91. package/dist/modules/index.js +16 -0
  92. package/dist/modules/types.d.ts +9 -0
  93. package/dist/modules/types.js +6 -0
  94. package/dist/modules/user.module.d.ts +10 -0
  95. package/dist/modules/user.module.js +4 -0
  96. package/dist/modules-C_2SF3he.js +1 -0
  97. package/dist/rate-limiter/in-memory-rate-limiter.d.ts +2 -0
  98. package/dist/rate-limiter/in-memory-rate-limiter.js +3 -0
  99. package/dist/rate-limiter/index.d.ts +3 -0
  100. package/dist/rate-limiter/index.js +4 -0
  101. package/dist/rate-limiter-BnvPGJOK.js +1 -0
  102. package/dist/repositories-nTfSJyvW.js +1 -0
  103. package/dist/request-logger-CK3SOnoz.d.ts +23 -0
  104. package/dist/request-logger-Cw1XQWTV.js +49 -0
  105. package/dist/request-logger-Cw1XQWTV.js.map +1 -0
  106. package/dist/structured-logger-BsxDI9zX.js +119 -0
  107. package/dist/structured-logger-BsxDI9zX.js.map +1 -0
  108. package/dist/structured-logger-Dz06Uz-u.d.ts +47 -0
  109. package/dist/transaction-akuz5Fch.d.ts +22 -0
  110. package/dist/transaction-r4Sy3eC-.js +35 -0
  111. package/dist/transaction-r4Sy3eC-.js.map +1 -0
  112. package/dist/types-65aFqB5L.d.ts +62 -0
  113. package/dist/use-case-decorator-DzPSPSv5.d.ts +52 -0
  114. package/dist/use-case-decorator-GmDeYViz.js +118 -0
  115. package/dist/use-case-decorator-GmDeYViz.js.map +1 -0
  116. package/dist/user.drizzle-9kkstnkV.d.ts +12 -0
  117. package/dist/user.drizzle-CgKIqqb3.js +57 -0
  118. package/dist/user.drizzle-CgKIqqb3.js.map +1 -0
  119. package/dist/user.module-BEpCbKsU.js +17 -0
  120. package/dist/user.module-BEpCbKsU.js.map +1 -0
  121. package/dist/user.module-D3lVJ98T.d.ts +15 -0
  122. package/dist/with-caching-BniS1aZd.d.ts +39 -0
  123. package/dist/with-caching-NmBxu7vJ.js +37 -0
  124. package/dist/with-caching-NmBxu7vJ.js.map +1 -0
  125. package/dist/with-rate-limit-Cp2V1RHn.js +48 -0
  126. package/dist/with-rate-limit-Cp2V1RHn.js.map +1 -0
  127. package/dist/with-rate-limit-DK4ZF-Qg.d.ts +45 -0
  128. package/dist/with-retry-B9-hUj7I.d.ts +40 -0
  129. package/dist/with-retry-coyYPiX1.js +49 -0
  130. package/dist/with-retry-coyYPiX1.js.map +1 -0
  131. package/package.json +10 -24
  132. package/src/index.ts +0 -26
package/dist/index.d.ts CHANGED
@@ -1,506 +1,29 @@
1
- import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
2
- import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
- import { Pool } from "pg";
4
- import { AwilixContainer } from "awilix";
5
- import { AppError, CacheStore, CacheStore as CacheStore$1, Clock, EventBus, EventHandler, EventName, EventPublisher, Logger, RateLimiterStore, RateLimiterStore as RateLimiterStore$1, TypedDomainEvent, User, UserRepository } from "@kuckit/domain";
6
- import { google } from "@ai-sdk/google";
7
- import { auth } from "@kuckit/auth";
8
- import { UserRepository as UserRepository$1 } from "@kuckit/domain/ports/user-repository";
9
- import { Logger as Logger$1 } from "@kuckit/domain/ports/logger";
10
-
11
- //#region src/db/drizzle/db.d.ts
12
- /**
13
- * Create database connection pool
14
- */
15
- declare const createDbPool: (connectionString: string) => Pool;
16
- /**
17
- * Create Drizzle instance from pool
18
- */
19
- declare const createDb: (pool: Pool) => drizzle_orm_node_postgres0.NodePgDatabase<Record<string, never>> & {
20
- $client: Pool;
21
- };
22
- //#endregion
23
- //#region src/db/drizzle/repositories/user.drizzle.d.ts
24
- /**
25
- * Drizzle implementation of UserRepository
26
- */
27
- declare const makeDrizzleUserRepository: (db: NodePgDatabase) => UserRepository$1;
28
- //#endregion
29
- //#region src/db/transaction.d.ts
30
- /**
31
- * Run a function within a database transaction
32
- * Creates a child scope with transaction-bound repositories
33
- *
34
- * Usage:
35
- * ```typescript
36
- * const result = await runInTransaction(container, async (txScope) => {
37
- * const { userRepository } = txScope.cradle
38
- * await userRepository.save(user)
39
- * return user
40
- * })
41
- * ```
42
- */
43
- declare const runInTransaction: <T>(container: AwilixContainer, fn: (txScope: AwilixContainer) => Promise<T>) => Promise<T>;
44
- type TransactionFn<T> = (txScope: AwilixContainer) => Promise<T>;
45
- //#endregion
46
- //#region ../domain/src/ports/logger.d.ts
47
- /**
48
- * Logger port - structured logging for Loki/Prometheus
49
- * Loki-compatible: labels and structured fields in meta
50
- */
51
- interface Logger$2 {
52
- debug: (message: string, meta?: LogContext) => void;
53
- info: (message: string, meta?: LogContext) => void;
54
- warn: (message: string, meta?: LogContext) => void;
55
- error: (message: string, meta?: LogContext | Error) => void;
56
- }
57
- /**
58
- * Structured log context (Loki labels)
59
- */
60
- interface LogContext {
61
- requestId?: string;
62
- userId?: string;
63
- feature?: string;
64
- [key: string]: any;
65
- }
66
- //#endregion
67
- //#region src/logging/structured-logger.d.ts
68
- type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
69
- /**
70
- * Structured logger implementation
71
- * - JSON logs compatible with Loki
72
- * - File + stdout support
73
- * - Prometheus metrics collection
74
- */
75
- declare class StructuredLogger implements Logger$2 {
76
- private options;
77
- private fileStream;
78
- private metrics;
79
- constructor(options?: {
80
- logDir?: string;
81
- enableFile?: boolean;
82
- minLevel?: LogLevel;
83
- });
84
- private initFileStream;
85
- debug(message: string, meta?: LogContext): void;
86
- info(message: string, meta?: LogContext): void;
87
- warn(message: string, meta?: LogContext): void;
88
- error(message: string, meta?: LogContext | Error): void;
89
- private log;
90
- private shouldSkip;
91
- private formatLog;
92
- /**
93
- * Get metrics in Prometheus text format
94
- */
95
- getMetrics(): string;
96
- /**
97
- * Cleanup resources
98
- */
99
- dispose(): Promise<void>;
100
- }
101
- /**
102
- * Create logger instance
103
- */
104
- declare const makeStructuredLogger: (options?: {
105
- logDir?: string;
106
- enableFile?: boolean;
107
- minLevel?: LogLevel;
108
- }) => StructuredLogger;
109
- //#endregion
110
- //#region src/logging/request-logger.d.ts
111
- /**
112
- * Options for creating a request-scoped logger
113
- */
114
- interface RequestLoggerOptions {
115
- requestId: string;
116
- userId?: string;
117
- baseLogger: Logger$1;
118
- }
119
- /**
120
- * Create a request-scoped logger that automatically includes
121
- * requestId and userId in all log entries.
122
- *
123
- * This wraps the base singleton logger and enriches all log
124
- * calls with request context for Loki-compatible structured logging.
125
- */
126
- declare const makeRequestLogger: (options: RequestLoggerOptions) => Logger$1;
127
- //#endregion
128
- //#region src/errors/error-handler.d.ts
129
- /**
130
- * Serialized error for API responses
131
- */
132
- interface SerializedError {
133
- code: string;
134
- message: string;
135
- statusCode: number;
136
- meta?: Record<string, any>;
137
- }
138
- /**
139
- * Error handler for structured error logging and serialization
140
- */
141
- declare class ErrorHandler {
142
- private logger;
143
- constructor(logger: Logger$2);
144
- /**
145
- * Handle error and serialize for API response
146
- */
147
- handle(error: unknown, context?: Record<string, any>): SerializedError;
148
- /**
149
- * Normalize any error to AppError
150
- */
151
- private normalize;
152
- /**
153
- * Log error with appropriate level
154
- */
155
- private log;
156
- /**
157
- * Serialize error for API response
158
- */
159
- private serialize;
160
- /**
161
- * Create error handler factory
162
- */
163
- static create(logger: Logger$2): ErrorHandler;
164
- }
165
- /**
166
- * Factory for error handler
167
- */
168
- declare const makeErrorHandler: (logger: Logger$2) => ErrorHandler;
169
- //#endregion
170
- //#region src/events/in-memory-event-bus.d.ts
171
- /**
172
- * In-memory event bus
173
- * Stores handlers in Sets, executes synchronously or asynchronously
174
- */
175
- declare class InMemoryEventBus implements EventBus {
176
- private logger;
177
- private handlers;
178
- private allHandlers;
179
- constructor(logger: Logger);
180
- publish<TName extends EventName>(event: TypedDomainEvent<TName>): Promise<void>;
181
- publishAsync<TName extends EventName>(event: TypedDomainEvent<TName>): void;
182
- subscribe<TName extends EventName>(eventName: TName, handler: EventHandler<TName>): () => void;
183
- subscribeAll(handler: EventHandler): () => void;
184
- }
185
- //#endregion
186
- //#region src/events/event-publisher-adapter.d.ts
187
- /**
188
- * Adapter that implements EventPublisher port using EventBus
189
- * Converts the simplified EventPublisher interface to full EventBus types
190
- */
191
- declare const makeEventPublisherAdapter: (eventBus: EventBus, logger: Logger) => EventPublisher;
192
- //#endregion
193
- //#region src/events/in-memory-event-publisher.d.ts
194
- /**
195
- * In-memory event publisher implementation
196
- * Suitable for development and testing
197
- */
198
- declare const makeInMemoryEventPublisher: () => EventPublisher;
199
- //#endregion
200
- //#region src/cache/in-memory-cache-store.d.ts
201
- /**
202
- * In-memory cache store implementation
203
- * Suitable for single-process applications or development
204
- * For distributed systems, use Redis adapter
205
- */
206
- declare class InMemoryCacheStore implements CacheStore$1 {
207
- private cleanupIntervalMs;
208
- private cache;
209
- private cleanupTimer;
210
- constructor(cleanupIntervalMs?: number);
211
- get<T>(key: string): Promise<T | undefined>;
212
- set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
213
- del(key: string): Promise<void>;
214
- clear(): Promise<void>;
215
- has(key: string): Promise<boolean>;
216
- /**
217
- * Start background cleanup of expired entries
218
- */
219
- private startCleanup;
220
- /**
221
- * Stop cleanup timer
222
- */
223
- destroy(): void;
224
- }
225
- //#endregion
226
- //#region src/rate-limiter/in-memory-rate-limiter.d.ts
227
- /**
228
- * In-memory rate limiter using token bucket algorithm
229
- * Suitable for single-process applications or development
230
- * For distributed systems, use Redis adapter
231
- */
232
- declare class InMemoryRateLimiterStore implements RateLimiterStore$1 {
233
- private cleanupIntervalMs;
234
- private buckets;
235
- private cleanupTimer;
236
- constructor(cleanupIntervalMs?: number);
237
- checkLimit(key: string, capacity: number, refillPerSecond: number): Promise<{
238
- allowed: boolean;
239
- tokensRemaining: number;
240
- resetAt: Date;
241
- }>;
242
- reset(key: string): Promise<void>;
243
- clear(): Promise<void>;
244
- /**
245
- * Start background cleanup of old buckets
246
- * Removes buckets that haven't been used in a long time
247
- */
248
- private startCleanup;
249
- /**
250
- * Stop cleanup timer
251
- */
252
- destroy(): void;
253
- }
254
- //#endregion
255
- //#region src/decorators/use-case-decorator.d.ts
256
- /**
257
- * Use case decorator type
258
- * Wraps a use case function with cross-cutting concerns
259
- */
260
- type UseCase<T extends (...args: any[]) => Promise<any>> = T;
261
- /**
262
- * Decorator context passed to all decorators
263
- */
264
- interface DecoratorContext {
265
- logger: Logger$2;
266
- requestId?: string;
267
- userId?: string;
268
- feature?: string;
269
- }
270
- /**
271
- * Performance metrics collected by decorator
272
- */
273
- interface PerformanceMetrics {
274
- startTime: number;
275
- endTime: number;
276
- durationMs: number;
277
- }
278
- /**
279
- * Base decorator that adds performance monitoring
280
- */
281
- declare const withPerformanceMonitoring: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
282
- /**
283
- * Base decorator that adds error handling and conversion
284
- */
285
- declare const withErrorHandling: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
286
- /**
287
- * Request tracing decorator - adds context to logs
288
- */
289
- declare const withRequestTracing: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
290
- /**
291
- * Compose multiple decorators together
292
- * Order: Tracing → Performance → Error Handling
293
- * (outermost → innermost)
294
- */
295
- declare const decorateUseCase: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
296
- /**
297
- * Factory for creating decorated use cases
298
- * Used in dependency injection to wrap use cases automatically
299
- */
300
- declare const makeDecoratedUseCase: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
301
- //#endregion
302
- //#region src/decorators/apply-decorators.d.ts
303
- /**
304
- * Helper to apply decorators to use cases in module registration
305
- * Reduces boilerplate in feature modules
306
- *
307
- * Usage:
308
- * ```
309
- * getUserProfile: asFunction(({ userRepository, ...deps }) =>
310
- * applyDecorators(
311
- * makeGetUserProfile({ userRepository }),
312
- * deps,
313
- * 'getUserProfile'
314
- * )
315
- * ).scoped(),
316
- * ```
317
- */
318
- declare const applyDecorators: <T extends (...args: any[]) => Promise<any>>(useCase: T, deps: {
319
- logger: any;
320
- requestId?: string;
321
- }, featureName: string) => T;
322
- //#endregion
323
- //#region src/decorators/with-caching.d.ts
324
- /**
325
- * Options for caching decorator
326
- */
327
- interface WithCachingOptions {
328
- /** Cache key function - maps input to cache key */
329
- keyFn: (input: any) => string;
330
- /** Time to live in milliseconds */
331
- ttlMs: number;
332
- /** Stale-while-revalidate: return stale value while refreshing in background */
333
- staleWhileRevalidateMs?: number;
334
- }
335
- /**
336
- * Wraps a use case with caching
337
- * - Only works with idempotent read operations
338
- * - Key function determines cache key from input
339
- * - TTL controls cache expiration
340
- * - SWR allows returning stale value while revalidating
341
- *
342
- * @example
343
- * ```ts
344
- * const cachedGetUser = withCaching(
345
- * getUserProfile,
346
- * cacheStore,
347
- * {
348
- * keyFn: (input) => `user:${input.userId}`,
349
- * ttlMs: 60000, // 1 minute
350
- * staleWhileRevalidateMs: 120000, // 2 minutes
351
- * }
352
- * )
353
- * ```
354
- */
355
- declare const withCaching: <I extends Record<string, any>, O>(fn: (input: I) => Promise<O>, cacheStore: CacheStore$1, options: WithCachingOptions) => ((input: I) => Promise<O>);
356
- //#endregion
357
- //#region src/decorators/with-retry.d.ts
358
- /**
359
- * Options for retry decorator
360
- */
361
- interface WithRetryOptions {
362
- /** Maximum number of retry attempts (default: 3) */
363
- maxAttempts?: number;
364
- /** Initial backoff in milliseconds (default: 100) */
365
- initialBackoffMs?: number;
366
- /** Maximum backoff in milliseconds (default: 30000) */
367
- maxBackoffMs?: number;
368
- /** Backoff multiplier for exponential backoff (default: 2) */
369
- backoffMultiplier?: number;
370
- /** Predicate to determine if error is retryable */
371
- retryOn?: (error: Error) => boolean;
372
- }
373
- /**
374
- * Wraps a use case with retry logic
375
- * - Uses exponential backoff
376
- * - Only retries on specific errors via retryOn predicate
377
- * - Backoff is capped at maxBackoffMs
378
- *
379
- * @example
380
- * ```ts
381
- * const retriedGetUser = withRetry(
382
- * getUserProfile,
383
- * {
384
- * maxAttempts: 3,
385
- * initialBackoffMs: 100,
386
- * maxBackoffMs: 30000,
387
- * backoffMultiplier: 2,
388
- * retryOn: (error) => error.message.includes('TIMEOUT'),
389
- * }
390
- * )
391
- * ```
392
- */
393
- declare const withRetry: <I extends any[], O>(fn: (...args: I) => Promise<O>, options?: WithRetryOptions) => ((...args: I) => Promise<O>);
394
- //#endregion
395
- //#region src/decorators/with-rate-limit.d.ts
396
- /**
397
- * Options for rate limiting decorator
398
- */
399
- interface WithRateLimitOptions {
400
- /** Rate limit key function - maps input to limit key */
401
- keyFn: (input: any) => string;
402
- /** Bucket capacity (max requests) */
403
- capacity: number;
404
- /** Tokens refilled per second */
405
- refillPerSecond: number;
406
- }
407
- /**
408
- * Rate limit error
409
- */
410
- declare class RateLimitError extends AppError {
411
- readonly resetAt: Date;
412
- constructor(resetAt: Date);
413
- }
414
- /**
415
- * Wraps a use case with rate limiting
416
- * - Uses token bucket algorithm
417
- * - Per-input rate limit tracking via keyFn
418
- * - Throws RateLimitError when limit exceeded
419
- *
420
- * @example
421
- * ```ts
422
- * const limitedCreatePost = withRateLimit(
423
- * createPost,
424
- * rateLimiterStore,
425
- * {
426
- * keyFn: (input) => `user:${input.userId}`,
427
- * capacity: 10,
428
- * refillPerSecond: 1, // 1 request per second
429
- * }
430
- * )
431
- * ```
432
- */
433
- declare const withRateLimit: <I extends Record<string, any>, O>(fn: (input: I) => Promise<O>, rateLimiterStore: RateLimiterStore$1, options: WithRateLimitOptions) => ((input: I) => Promise<O>);
434
- //#endregion
435
- //#region src/modules/types.d.ts
436
- /**
437
- * Application configuration
438
- */
439
- interface Config {
440
- databaseUrl: string;
441
- port: number;
442
- corsOrigin: string;
443
- googleAiApiKey: string;
444
- logLevel: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
445
- enableFileLogging: boolean;
446
- logDir: string;
447
- }
448
- /**
449
- * Typed Cradle interface for full type safety
450
- * Includes all registrations from all modules
451
- */
452
- interface Cradle {
453
- config: Config;
454
- dbPool: Pool;
455
- db: ReturnType<typeof createDb>;
456
- clock: Clock;
457
- logger: Logger & StructuredLogger;
458
- errorHandler: ErrorHandler;
459
- auth: typeof auth;
460
- aiProvider: ReturnType<typeof google>;
461
- eventBus: EventBus;
462
- cacheStore: CacheStore$1;
463
- rateLimiterStore: RateLimiterStore$1;
464
- userRepository: UserRepository;
465
- getUserProfile: (input: {
466
- userId: string;
467
- }) => Promise<User>;
468
- updateUserProfile: (input: {
469
- userId: string;
470
- updates: Partial<{
471
- name: string;
472
- email: string;
473
- }>;
474
- }) => Promise<User>;
475
- createUser: (input: {
476
- name: string;
477
- email: string;
478
- emailVerified: boolean;
479
- }) => Promise<User>;
480
- eventPublisher: EventPublisher;
481
- session?: any;
482
- requestId: string;
483
- requestLogger: Logger;
484
- }
485
- //#endregion
486
- //#region src/modules/core.module.d.ts
487
- /**
488
- * Core module: singleton registrations for infrastructure
489
- * - Database pool and connection
490
- * - Clock
491
- * - Logger (structured, Loki/Prometheus compatible)
492
- * - AI provider
493
- * - Auth
494
- */
495
- declare const registerCoreModule: (container: AwilixContainer<Cradle>) => void;
496
- //#endregion
497
- //#region src/modules/user.module.d.ts
498
- /**
499
- * User repository module: registers user-related repositories
500
- *
501
- * Note: Use case registrations are in apps/server/src/modules/user.module.ts
502
- * to maintain Clean Architecture layering (Infrastructure should not import Application)
503
- */
504
- declare const registerUserModule: (container: AwilixContainer<Cradle>) => void;
505
- //#endregion
506
- export { type CacheStore, type Config, type Cradle, type DecoratorContext, ErrorHandler, InMemoryCacheStore, InMemoryEventBus, InMemoryRateLimiterStore, type PerformanceMetrics, RateLimitError, type RateLimiterStore, RequestLoggerOptions, SerializedError, StructuredLogger, type TransactionFn, type UseCase, type WithCachingOptions, type WithRateLimitOptions, type WithRetryOptions, applyDecorators, createDb, createDbPool, decorateUseCase, makeDecoratedUseCase, makeDrizzleUserRepository, makeErrorHandler, makeEventPublisherAdapter, makeInMemoryEventPublisher, makeRequestLogger, makeStructuredLogger, registerCoreModule, registerUserModule, runInTransaction, withCaching, withErrorHandling, withPerformanceMonitoring, withRateLimit, withRequestTracing, withRetry };
1
+ import { t as InMemoryCacheStore } from "./in-memory-cache-store-BaRxM--K.js";
2
+ import { t as CacheStore } from "./index-C6nYd7xV.js";
3
+ import { n as createDbPool, t as createDb } from "./db-tAPHBDyL.js";
4
+ import { t as makeDrizzleUserRepository } from "./user.drizzle-9kkstnkV.js";
5
+ import "./index-B5F3AfVc.js";
6
+ import { n as runInTransaction, t as TransactionFn } from "./transaction-akuz5Fch.js";
7
+ import { t as applyDecorators } from "./apply-decorators-CW23qWy7.js";
8
+ import "./logger-Bl10drB8.js";
9
+ import { a as makeDecoratedUseCase, c as withRequestTracing, i as decorateUseCase, n as PerformanceMetrics, o as withErrorHandling, r as UseCase, s as withPerformanceMonitoring, t as DecoratorContext } from "./use-case-decorator-DzPSPSv5.js";
10
+ import { n as withCaching, t as WithCachingOptions } from "./with-caching-BniS1aZd.js";
11
+ import { n as withRetry, t as WithRetryOptions } from "./with-retry-B9-hUj7I.js";
12
+ import { n as WithRateLimitOptions, r as withRateLimit, t as RateLimitError } from "./with-rate-limit-DK4ZF-Qg.js";
13
+ import "./index-DXJbbtWQ.js";
14
+ import { n as SerializedError, r as makeErrorHandler, t as ErrorHandler } from "./error-handler-BDid7SIZ.js";
15
+ import "./index-LKrIp3Oo.js";
16
+ import { t as makeEventPublisherAdapter } from "./event-publisher-adapter-CpxK0OJ3.js";
17
+ import { t as InMemoryEventBus } from "./in-memory-event-bus-CqIBLRze.js";
18
+ import { t as makeInMemoryEventPublisher } from "./in-memory-event-publisher-CxOQ-hnq.js";
19
+ import "./index-C0yeuOwC.js";
20
+ import { n as makeStructuredLogger, t as StructuredLogger } from "./structured-logger-Dz06Uz-u.js";
21
+ import { n as makeRequestLogger, t as RequestLoggerOptions } from "./request-logger-CK3SOnoz.js";
22
+ import "./index-DVGDAddE.js";
23
+ import { t as InMemoryRateLimiterStore } from "./in-memory-rate-limiter-DJsxdZZR.js";
24
+ import { t as RateLimiterStore } from "./index-BH67NKRs.js";
25
+ import { n as Cradle, t as Config } from "./types-65aFqB5L.js";
26
+ import { t as registerCoreModule } from "./core.module-B1TdC0yX.js";
27
+ import { t as registerUserModule } from "./user.module-D3lVJ98T.js";
28
+ import "./index-B7z6dpFd.js";
29
+ export { CacheStore, type Config, type Cradle, DecoratorContext, ErrorHandler, InMemoryCacheStore, InMemoryEventBus, InMemoryRateLimiterStore, PerformanceMetrics, RateLimitError, RateLimiterStore, RequestLoggerOptions, SerializedError, StructuredLogger, type TransactionFn, UseCase, WithCachingOptions, WithRateLimitOptions, WithRetryOptions, applyDecorators, createDb, createDbPool, decorateUseCase, makeDecoratedUseCase, makeDrizzleUserRepository, makeErrorHandler, makeEventPublisherAdapter, makeInMemoryEventPublisher, makeRequestLogger, makeStructuredLogger, registerCoreModule, registerUserModule, runInTransaction, withCaching, withErrorHandling, withPerformanceMonitoring, withRateLimit, withRequestTracing, withRetry };