@kuckit/infrastructure 2.0.3 → 2.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.
- package/dist/{apply-decorators-CaHIAL5X.js → apply-decorators-DA33OBa7.js} +2 -2
- package/dist/{apply-decorators-CaHIAL5X.js.map → apply-decorators-DA33OBa7.js.map} +1 -1
- package/dist/{apply-decorators-CW23qWy7.d.ts → apply-decorators-zka0zqoX.d.ts} +1 -1
- package/dist/cache/in-memory-cache-store.d.ts +1 -1
- package/dist/cache/in-memory-cache-store.js +1 -1
- package/dist/cache/index.d.ts +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/{core.module-_mfoxc8b.d.ts → core.module-BEuDFLDA.d.ts} +2 -2
- package/dist/{core.module-ehJ0bdNr.js → core.module-oSFmg8ER.js} +5 -5
- package/dist/{core.module-ehJ0bdNr.js.map → core.module-oSFmg8ER.js.map} +1 -1
- package/dist/db/drizzle/db.d.ts +1 -1
- package/dist/db/drizzle/repositories/index.d.ts +2 -2
- package/dist/db/drizzle/repositories/user.drizzle.d.ts +1 -1
- package/dist/db/transaction.d.ts +1 -1
- package/dist/{db-tAPHBDyL.d.ts → db-Brm6l10l.d.ts} +1 -1
- package/dist/decorators/apply-decorators.d.ts +1 -1
- package/dist/decorators/apply-decorators.js +2 -3
- package/dist/decorators/index.d.ts +6 -7
- package/dist/decorators/index.js +6 -7
- package/dist/decorators/use-case-decorator.d.ts +1 -2
- package/dist/decorators/use-case-decorator.js +1 -2
- package/dist/decorators/with-caching.d.ts +1 -1
- package/dist/decorators/with-caching.js +1 -1
- package/dist/decorators/with-rate-limit.d.ts +1 -1
- package/dist/decorators/with-rate-limit.js +1 -1
- package/dist/decorators/with-retry.d.ts +1 -1
- package/dist/decorators/with-retry.js +1 -1
- package/dist/{error-handler-D4s_TTI1.js → error-handler-B4kyoFfy.js} +22 -5
- package/dist/error-handler-B4kyoFfy.js.map +1 -0
- package/dist/{error-handler-BDid7SIZ.d.ts → error-handler-Up4XIzWt.d.ts} +8 -4
- package/dist/errors/error-handler.d.ts +1 -2
- package/dist/errors/error-handler.js +1 -2
- package/dist/errors/index.d.ts +2 -3
- package/dist/errors/index.js +2 -3
- package/dist/{event-publisher-adapter-B02oKEmP.js → event-publisher-adapter-BHioo53u.js} +1 -1
- package/dist/{event-publisher-adapter-B02oKEmP.js.map → event-publisher-adapter-BHioo53u.js.map} +1 -1
- package/dist/{event-publisher-adapter-CpxK0OJ3.d.ts → event-publisher-adapter-DZv-0P_I.d.ts} +1 -1
- package/dist/events/event-publisher-adapter.d.ts +1 -1
- package/dist/events/event-publisher-adapter.js +1 -1
- package/dist/events/in-memory-event-bus.d.ts +1 -1
- package/dist/events/in-memory-event-bus.js +1 -1
- package/dist/events/in-memory-event-publisher.d.ts +1 -1
- package/dist/events/in-memory-event-publisher.js +1 -1
- package/dist/events/index.d.ts +4 -4
- package/dist/events/index.js +4 -4
- package/dist/{in-memory-cache-store-DSdz35Ve.d.ts → in-memory-cache-store-B1RVPPwh.d.ts} +1 -1
- package/dist/{in-memory-cache-store-BA-Eqsf0.js → in-memory-cache-store-C-v4ag_e.js} +1 -1
- package/dist/{in-memory-cache-store-BA-Eqsf0.js.map → in-memory-cache-store-C-v4ag_e.js.map} +1 -1
- package/dist/{in-memory-event-bus-CqIBLRze.d.ts → in-memory-event-bus-0rhMMoai.d.ts} +1 -1
- package/dist/{in-memory-event-bus-BCyPrNAE.js → in-memory-event-bus-D0n7i3uf.js} +1 -1
- package/dist/{in-memory-event-bus-BCyPrNAE.js.map → in-memory-event-bus-D0n7i3uf.js.map} +1 -1
- package/dist/{in-memory-event-publisher-CxOQ-hnq.d.ts → in-memory-event-publisher-BuFGCWeP.d.ts} +1 -1
- package/dist/{in-memory-event-publisher-BdOlxfkx.js → in-memory-event-publisher-DEMC6qBo.js} +1 -1
- package/dist/{in-memory-event-publisher-BdOlxfkx.js.map → in-memory-event-publisher-DEMC6qBo.js.map} +1 -1
- package/dist/{in-memory-rate-limiter-DKOwxFD7.js → in-memory-rate-limiter-ClGoFbk6.js} +1 -1
- package/dist/{in-memory-rate-limiter-DKOwxFD7.js.map → in-memory-rate-limiter-ClGoFbk6.js.map} +1 -1
- package/dist/{in-memory-rate-limiter-DZqM4MOS.d.ts → in-memory-rate-limiter-DjyLAj3S.d.ts} +1 -1
- package/dist/index.d.ts +26 -27
- package/dist/index.js +19 -20
- package/dist/logging/index.d.ts +3 -4
- package/dist/logging/request-logger.d.ts +1 -1
- package/dist/logging/structured-logger.d.ts +1 -2
- package/dist/modules/core.module.d.ts +8 -9
- package/dist/modules/core.module.js +6 -7
- package/dist/modules/index.d.ts +10 -11
- package/dist/modules/index.js +8 -9
- package/dist/modules/types.d.ts +7 -8
- package/dist/modules/user.module.d.ts +8 -9
- package/dist/modules/user.module.js +1 -1
- package/dist/rate-limiter/in-memory-rate-limiter.d.ts +1 -1
- package/dist/rate-limiter/in-memory-rate-limiter.js +1 -1
- package/dist/rate-limiter/index.d.ts +2 -2
- package/dist/rate-limiter/index.js +2 -2
- package/dist/request-logger-Cw1XQWTV.js.map +1 -1
- package/dist/{request-logger-CK3SOnoz.d.ts → request-logger-z3FaJPry.d.ts} +2 -2
- package/dist/structured-logger-BsxDI9zX.js.map +1 -1
- package/dist/{structured-logger-DyrZwR3S.d.ts → structured-logger-DJJ-0mnW.d.ts} +2 -2
- package/dist/{transaction-akuz5Fch.d.ts → transaction-D961784D.d.ts} +1 -1
- package/dist/{types-BnE7rffD.d.ts → types-BDBUcrxL.d.ts} +4 -4
- package/dist/{use-case-decorator-DzPSPSv5.d.ts → use-case-decorator-D9fX_4EY.d.ts} +2 -2
- package/dist/{use-case-decorator-GmDeYViz.js → use-case-decorator-DRIN79Vt.js} +2 -2
- package/dist/use-case-decorator-DRIN79Vt.js.map +1 -0
- package/dist/{user.drizzle-9kkstnkV.d.ts → user.drizzle-SbUroSiT.d.ts} +1 -1
- package/dist/{user.module-DqTfy_MM.d.ts → user.module-DWDd3hGF.d.ts} +2 -2
- package/dist/{user.module-BEpCbKsU.js → user.module-iUC-HTqT.js} +1 -1
- package/dist/{user.module-BEpCbKsU.js.map → user.module-iUC-HTqT.js.map} +1 -1
- package/dist/{with-caching-NmBxu7vJ.js → with-caching-DjOW2Xjh.js} +1 -1
- package/dist/{with-caching-NmBxu7vJ.js.map → with-caching-DjOW2Xjh.js.map} +1 -1
- package/dist/{with-caching-BniS1aZd.d.ts → with-caching-c8PLIWLG.d.ts} +1 -1
- package/dist/{with-rate-limit-Cp2V1RHn.js → with-rate-limit-B1L4rZzs.js} +1 -1
- package/dist/{with-rate-limit-Cp2V1RHn.js.map → with-rate-limit-B1L4rZzs.js.map} +1 -1
- package/dist/{with-rate-limit-DK4ZF-Qg.d.ts → with-rate-limit-CK5GHSfo.d.ts} +1 -1
- package/dist/{with-retry-coyYPiX1.js → with-retry-BFh_Hn_O.js} +1 -1
- package/dist/{with-retry-coyYPiX1.js.map → with-retry-BFh_Hn_O.js.map} +1 -1
- package/dist/{with-retry-B9-hUj7I.d.ts → with-retry-q6ftxgF2.d.ts} +1 -1
- package/package.json +4 -4
- package/dist/error-handler-D4s_TTI1.js.map +0 -1
- package/dist/errors-BB_jeye8.js +0 -43
- package/dist/errors-BB_jeye8.js.map +0 -1
- package/dist/logger-Bl10drB8.d.ts +0 -23
- package/dist/use-case-decorator-GmDeYViz.js.map +0 -1
- /package/dist/{cache-BjdZ-Ye4.js → cache-d2O3d-0Z.js} +0 -0
- /package/dist/{decorators-CqyPE9AQ.js → decorators-CW7geFqk.js} +0 -0
- /package/dist/{errors-DfkerzdO.js → errors-DXbNwomE.js} +0 -0
- /package/dist/{events-Dqynhuj2.js → events-DkUA7Khm.js} +0 -0
- /package/dist/{index-BH67NKRs.d.ts → index-B8lmalaK.d.ts} +0 -0
- /package/dist/{index-C6nYd7xV.d.ts → index-BS25w2a5.d.ts} +0 -0
- /package/dist/{index-B5F3AfVc.d.ts → index-CRDznOKQ.d.ts} +0 -0
- /package/dist/{index-B7z6dpFd.d.ts → index-Cg5cFzs-.d.ts} +0 -0
- /package/dist/{index-C0yeuOwC.d.ts → index-CuY8tqBC.d.ts} +0 -0
- /package/dist/{index-DVGDAddE.d.ts → index-LOv54jhI.d.ts} +0 -0
- /package/dist/{index-LKrIp3Oo.d.ts → index-kr8Wk7v5.d.ts} +0 -0
- /package/dist/{modules-C_2SF3he.js → modules-BICEbyjm.js} +0 -0
- /package/dist/{rate-limiter-BnvPGJOK.js → rate-limiter-DhcBdNmF.js} +0 -0
package/dist/{in-memory-rate-limiter-DKOwxFD7.js.map → in-memory-rate-limiter-ClGoFbk6.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-rate-limiter-
|
|
1
|
+
{"version":3,"file":"in-memory-rate-limiter-ClGoFbk6.js","names":["cleanupIntervalMs: number"],"sources":["../src/rate-limiter/in-memory-rate-limiter.ts"],"sourcesContent":["import type { RateLimiterStore } from '@kuckit/domain'\n\ninterface TokenBucket {\n\ttokens: number\n\tlastRefillAt: number\n}\n\n/**\n * In-memory rate limiter using token bucket algorithm\n * Suitable for single-process applications or development\n * For distributed systems, use Redis adapter\n *\n * NOTE: Call startCleanup() after construction to enable background cleanup,\n * or use makeInMemoryRateLimiterStore() factory which does this automatically.\n */\nexport class InMemoryRateLimiterStore implements RateLimiterStore {\n\tprivate buckets = new Map<string, TokenBucket>()\n\tprivate cleanupTimer: NodeJS.Timeout | null = null\n\n\tconstructor(private cleanupIntervalMs: number = 60000) {\n\t\t// Timer is NOT started in constructor to avoid side effects on import.\n\t\t// Call startCleanup() explicitly after construction.\n\t}\n\n\tasync checkLimit(\n\t\tkey: string,\n\t\tcapacity: number,\n\t\trefillPerSecond: number\n\t): Promise<{\n\t\tallowed: boolean\n\t\ttokensRemaining: number\n\t\tresetAt: Date\n\t}> {\n\t\tconst now = Date.now()\n\t\tlet bucket = this.buckets.get(key)\n\n\t\t// Initialize bucket if not exists\n\t\tif (!bucket) {\n\t\t\tbucket = {\n\t\t\t\ttokens: capacity,\n\t\t\t\tlastRefillAt: now,\n\t\t\t}\n\t\t\tthis.buckets.set(key, bucket)\n\t\t}\n\n\t\t// Calculate refill amount based on time passed\n\t\tconst timeSinceRefillMs = now - bucket.lastRefillAt\n\t\tconst timeSinceRefillSec = timeSinceRefillMs / 1000\n\t\tconst tokensToAdd = timeSinceRefillSec * refillPerSecond\n\n\t\t// Refill tokens (capped at capacity)\n\t\tbucket.tokens = Math.min(capacity, bucket.tokens + tokensToAdd)\n\t\tbucket.lastRefillAt = now\n\n\t\t// Check if request is allowed\n\t\tconst allowed = bucket.tokens >= 1\n\n\t\tif (allowed) {\n\t\t\tbucket.tokens -= 1\n\t\t}\n\n\t\t// Calculate reset time (when we'll have 1 token again)\n\t\tconst tokensNeeded = Math.max(0, 1 - bucket.tokens)\n\t\tconst secondsToReset = tokensNeeded / refillPerSecond\n\t\tconst resetAt = new Date(now + secondsToReset * 1000)\n\n\t\treturn {\n\t\t\tallowed,\n\t\t\ttokensRemaining: Math.floor(bucket.tokens),\n\t\t\tresetAt,\n\t\t}\n\t}\n\n\tasync reset(key: string): Promise<void> {\n\t\tthis.buckets.delete(key)\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tthis.buckets.clear()\n\t}\n\n\t/**\n\t * Start background cleanup of old buckets\n\t * Removes buckets that haven't been used in a long time\n\t * Call this after construction to enable automatic cleanup.\n\t */\n\tstartCleanup(): void {\n\t\tif (this.cleanupTimer) return // Already running\n\n\t\tthis.cleanupTimer = setInterval(() => {\n\t\t\tconst now = Date.now()\n\t\t\tconst maxAgeMs = 3600000 // 1 hour\n\t\t\tlet removed = 0\n\n\t\t\tfor (const [key, bucket] of this.buckets.entries()) {\n\t\t\t\tif (now - bucket.lastRefillAt > maxAgeMs) {\n\t\t\t\t\tthis.buckets.delete(key)\n\t\t\t\t\tremoved++\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Optionally log cleanup metrics\n\t\t\tif (removed > 0) {\n\t\t\t\t// console.debug(`RateLimiter cleanup: removed ${removed} old buckets`)\n\t\t\t}\n\t\t}, this.cleanupIntervalMs)\n\t}\n\n\t/**\n\t * Stop cleanup timer\n\t */\n\tstopCleanup(): void {\n\t\tif (this.cleanupTimer) {\n\t\t\tclearInterval(this.cleanupTimer)\n\t\t\tthis.cleanupTimer = null\n\t\t}\n\t}\n\n\t/**\n\t * Stop cleanup timer (alias for stopCleanup)\n\t * @deprecated Use stopCleanup() instead\n\t */\n\tdestroy(): void {\n\t\tthis.stopCleanup()\n\t}\n}\n\n/**\n * Factory function that creates an InMemoryRateLimiterStore with cleanup started.\n * Use this in DI container registrations.\n */\nexport function makeInMemoryRateLimiterStore(cleanupIntervalMs = 60000): InMemoryRateLimiterStore {\n\tconst store = new InMemoryRateLimiterStore(cleanupIntervalMs)\n\tstore.startCleanup()\n\treturn store\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,2BAAb,MAAkE;CACjE,AAAQ,0BAAU,IAAI,KAA0B;CAChD,AAAQ,eAAsC;CAE9C,YAAY,AAAQA,oBAA4B,KAAO;EAAnC;;CAKpB,MAAM,WACL,KACA,UACA,iBAKE;EACF,MAAM,MAAM,KAAK,KAAK;EACtB,IAAI,SAAS,KAAK,QAAQ,IAAI,IAAI;AAGlC,MAAI,CAAC,QAAQ;AACZ,YAAS;IACR,QAAQ;IACR,cAAc;IACd;AACD,QAAK,QAAQ,IAAI,KAAK,OAAO;;EAM9B,MAAM,eAFoB,MAAM,OAAO,gBACQ,MACN;AAGzC,SAAO,SAAS,KAAK,IAAI,UAAU,OAAO,SAAS,YAAY;AAC/D,SAAO,eAAe;EAGtB,MAAM,UAAU,OAAO,UAAU;AAEjC,MAAI,QACH,QAAO,UAAU;EAKlB,MAAM,iBADe,KAAK,IAAI,GAAG,IAAI,OAAO,OAAO,GACb;EACtC,MAAM,UAAU,IAAI,KAAK,MAAM,iBAAiB,IAAK;AAErD,SAAO;GACN;GACA,iBAAiB,KAAK,MAAM,OAAO,OAAO;GAC1C;GACA;;CAGF,MAAM,MAAM,KAA4B;AACvC,OAAK,QAAQ,OAAO,IAAI;;CAGzB,MAAM,QAAuB;AAC5B,OAAK,QAAQ,OAAO;;;;;;;CAQrB,eAAqB;AACpB,MAAI,KAAK,aAAc;AAEvB,OAAK,eAAe,kBAAkB;GACrC,MAAM,MAAM,KAAK,KAAK;GACtB,MAAM,WAAW;GACjB,IAAI,UAAU;AAEd,QAAK,MAAM,CAAC,KAAK,WAAW,KAAK,QAAQ,SAAS,CACjD,KAAI,MAAM,OAAO,eAAe,UAAU;AACzC,SAAK,QAAQ,OAAO,IAAI;AACxB;;AAKF,OAAI,UAAU,GAAG;KAGf,KAAK,kBAAkB;;;;;CAM3B,cAAoB;AACnB,MAAI,KAAK,cAAc;AACtB,iBAAc,KAAK,aAAa;AAChC,QAAK,eAAe;;;;;;;CAQtB,UAAgB;AACf,OAAK,aAAa;;;;;;;AAQpB,SAAgB,6BAA6B,oBAAoB,KAAiC;CACjG,MAAM,QAAQ,IAAI,yBAAyB,kBAAkB;AAC7D,OAAM,cAAc;AACpB,QAAO"}
|
|
@@ -45,4 +45,4 @@ declare class InMemoryRateLimiterStore implements RateLimiterStore {
|
|
|
45
45
|
declare function makeInMemoryRateLimiterStore(cleanupIntervalMs?: number): InMemoryRateLimiterStore;
|
|
46
46
|
//#endregion
|
|
47
47
|
export { makeInMemoryRateLimiterStore as n, InMemoryRateLimiterStore as t };
|
|
48
|
-
//# sourceMappingURL=in-memory-rate-limiter-
|
|
48
|
+
//# sourceMappingURL=in-memory-rate-limiter-DjyLAj3S.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import { n as makeInMemoryCacheStore, t as InMemoryCacheStore } from "./in-memory-cache-store-
|
|
2
|
-
import { t as CacheStore } from "./index-
|
|
3
|
-
import { n as createDbPool, t as createDb } from "./db-
|
|
4
|
-
import { t as makeDrizzleUserRepository } from "./user.drizzle-
|
|
5
|
-
import "./index-
|
|
6
|
-
import { n as runInTransaction, t as TransactionFn } from "./transaction-
|
|
7
|
-
import { t as applyDecorators } from "./apply-decorators-
|
|
8
|
-
import "./
|
|
9
|
-
import {
|
|
10
|
-
import { n as
|
|
11
|
-
import { n as
|
|
12
|
-
import
|
|
1
|
+
import { n as makeInMemoryCacheStore, t as InMemoryCacheStore } from "./in-memory-cache-store-B1RVPPwh.js";
|
|
2
|
+
import { t as CacheStore } from "./index-BS25w2a5.js";
|
|
3
|
+
import { n as createDbPool, t as createDb } from "./db-Brm6l10l.js";
|
|
4
|
+
import { t as makeDrizzleUserRepository } from "./user.drizzle-SbUroSiT.js";
|
|
5
|
+
import "./index-kr8Wk7v5.js";
|
|
6
|
+
import { n as runInTransaction, t as TransactionFn } from "./transaction-D961784D.js";
|
|
7
|
+
import { t as applyDecorators } from "./apply-decorators-zka0zqoX.js";
|
|
8
|
+
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-D9fX_4EY.js";
|
|
9
|
+
import { n as withCaching, t as WithCachingOptions } from "./with-caching-c8PLIWLG.js";
|
|
10
|
+
import { n as withRetry, t as WithRetryOptions } from "./with-retry-q6ftxgF2.js";
|
|
11
|
+
import { n as WithRateLimitOptions, r as withRateLimit, t as RateLimitError } from "./with-rate-limit-CK5GHSfo.js";
|
|
12
|
+
import "./index-LOv54jhI.js";
|
|
13
|
+
import { n as SerializedError, r as makeErrorHandler, t as ErrorHandler } from "./error-handler-Up4XIzWt.js";
|
|
13
14
|
import "./index-DXJbbtWQ.js";
|
|
14
|
-
import {
|
|
15
|
-
import "./
|
|
16
|
-
import { t as
|
|
17
|
-
import
|
|
18
|
-
import { t as
|
|
19
|
-
import "./
|
|
20
|
-
import
|
|
21
|
-
import { n as
|
|
22
|
-
import "./index-
|
|
23
|
-
import { n as
|
|
24
|
-
import { t as
|
|
25
|
-
import {
|
|
26
|
-
import
|
|
27
|
-
import { t as registerUserModule } from "./user.module-DqTfy_MM.js";
|
|
28
|
-
import "./index-B7z6dpFd.js";
|
|
15
|
+
import { t as makeEventPublisherAdapter } from "./event-publisher-adapter-DZv-0P_I.js";
|
|
16
|
+
import { t as InMemoryEventBus } from "./in-memory-event-bus-0rhMMoai.js";
|
|
17
|
+
import { t as makeInMemoryEventPublisher } from "./in-memory-event-publisher-BuFGCWeP.js";
|
|
18
|
+
import "./index-CRDznOKQ.js";
|
|
19
|
+
import { n as StructuredLogger, r as makeStructuredLogger, t as LogLevel } from "./structured-logger-DJJ-0mnW.js";
|
|
20
|
+
import { n as makeRequestLogger, t as RequestLoggerOptions } from "./request-logger-z3FaJPry.js";
|
|
21
|
+
import "./index-CuY8tqBC.js";
|
|
22
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "./in-memory-rate-limiter-DjyLAj3S.js";
|
|
23
|
+
import { t as RateLimiterStore } from "./index-B8lmalaK.js";
|
|
24
|
+
import { n as Cradle, t as Config } from "./types-BDBUcrxL.js";
|
|
25
|
+
import { t as registerCoreModule } from "./core.module-BEuDFLDA.js";
|
|
26
|
+
import { t as registerUserModule } from "./user.module-DWDd3hGF.js";
|
|
27
|
+
import "./index-Cg5cFzs-.js";
|
|
29
28
|
export { CacheStore, type Config, type Cradle, DecoratorContext, ErrorHandler, InMemoryCacheStore, InMemoryEventBus, InMemoryRateLimiterStore, LogLevel, PerformanceMetrics, RateLimitError, RateLimiterStore, RequestLoggerOptions, SerializedError, StructuredLogger, type TransactionFn, UseCase, WithCachingOptions, WithRateLimitOptions, WithRetryOptions, applyDecorators, createDb, createDbPool, decorateUseCase, makeDecoratedUseCase, makeDrizzleUserRepository, makeErrorHandler, makeEventPublisherAdapter, makeInMemoryCacheStore, makeInMemoryEventPublisher, makeInMemoryRateLimiterStore, makeRequestLogger, makeStructuredLogger, registerCoreModule, registerUserModule, runInTransaction, withCaching, withErrorHandling, withPerformanceMonitoring, withRateLimit, withRequestTracing, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -5,25 +5,24 @@ import { t as runInTransaction } from "./transaction-r4Sy3eC-.js";
|
|
|
5
5
|
import { n as makeStructuredLogger, t as StructuredLogger } from "./structured-logger-BsxDI9zX.js";
|
|
6
6
|
import { t as makeRequestLogger } from "./request-logger-Cw1XQWTV.js";
|
|
7
7
|
import "./logging-4mLSrMc6.js";
|
|
8
|
-
import "./
|
|
9
|
-
import
|
|
10
|
-
import "./
|
|
11
|
-
import { t as
|
|
12
|
-
import { t as
|
|
13
|
-
import
|
|
14
|
-
import "./
|
|
15
|
-
import
|
|
16
|
-
import "./
|
|
17
|
-
import
|
|
18
|
-
import "./
|
|
19
|
-
import {
|
|
20
|
-
import { t as
|
|
21
|
-
import { t as
|
|
22
|
-
import { t as
|
|
23
|
-
import
|
|
24
|
-
import "./
|
|
25
|
-
import { t as
|
|
26
|
-
import
|
|
27
|
-
import "./modules-C_2SF3he.js";
|
|
8
|
+
import { n as makeErrorHandler, t as ErrorHandler } from "./error-handler-B4kyoFfy.js";
|
|
9
|
+
import "./errors-DXbNwomE.js";
|
|
10
|
+
import { t as InMemoryEventBus } from "./in-memory-event-bus-D0n7i3uf.js";
|
|
11
|
+
import { t as makeEventPublisherAdapter } from "./event-publisher-adapter-BHioo53u.js";
|
|
12
|
+
import { t as makeInMemoryEventPublisher } from "./in-memory-event-publisher-DEMC6qBo.js";
|
|
13
|
+
import "./events-DkUA7Khm.js";
|
|
14
|
+
import { n as makeInMemoryCacheStore, t as InMemoryCacheStore } from "./in-memory-cache-store-C-v4ag_e.js";
|
|
15
|
+
import "./cache-d2O3d-0Z.js";
|
|
16
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "./in-memory-rate-limiter-ClGoFbk6.js";
|
|
17
|
+
import "./rate-limiter-DhcBdNmF.js";
|
|
18
|
+
import { a as withRequestTracing, i as withPerformanceMonitoring, n as makeDecoratedUseCase, r as withErrorHandling, t as decorateUseCase } from "./use-case-decorator-DRIN79Vt.js";
|
|
19
|
+
import { t as applyDecorators } from "./apply-decorators-DA33OBa7.js";
|
|
20
|
+
import { t as withCaching } from "./with-caching-DjOW2Xjh.js";
|
|
21
|
+
import { t as withRetry } from "./with-retry-BFh_Hn_O.js";
|
|
22
|
+
import { n as withRateLimit, t as RateLimitError } from "./with-rate-limit-B1L4rZzs.js";
|
|
23
|
+
import "./decorators-CW7geFqk.js";
|
|
24
|
+
import { t as registerCoreModule } from "./core.module-oSFmg8ER.js";
|
|
25
|
+
import { t as registerUserModule } from "./user.module-iUC-HTqT.js";
|
|
26
|
+
import "./modules-BICEbyjm.js";
|
|
28
27
|
|
|
29
28
|
export { ErrorHandler, InMemoryCacheStore, InMemoryEventBus, InMemoryRateLimiterStore, RateLimitError, StructuredLogger, applyDecorators, createDb, createDbPool, decorateUseCase, makeDecoratedUseCase, makeDrizzleUserRepository, makeErrorHandler, makeEventPublisherAdapter, makeInMemoryCacheStore, makeInMemoryEventPublisher, makeInMemoryRateLimiterStore, makeRequestLogger, makeStructuredLogger, registerCoreModule, registerUserModule, runInTransaction, withCaching, withErrorHandling, withPerformanceMonitoring, withRateLimit, withRequestTracing, withRetry };
|
package/dist/logging/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import "../logger-
|
|
2
|
-
import { n as
|
|
3
|
-
import
|
|
4
|
-
import "../index-DVGDAddE.js";
|
|
1
|
+
import { n as StructuredLogger, r as makeStructuredLogger, t as LogLevel } from "../structured-logger-DJJ-0mnW.js";
|
|
2
|
+
import { n as makeRequestLogger, t as RequestLoggerOptions } from "../request-logger-z3FaJPry.js";
|
|
3
|
+
import "../index-CuY8tqBC.js";
|
|
5
4
|
export { LogLevel, RequestLoggerOptions, StructuredLogger, makeRequestLogger, makeStructuredLogger };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as makeRequestLogger, t as RequestLoggerOptions } from "../request-logger-
|
|
1
|
+
import { n as makeRequestLogger, t as RequestLoggerOptions } from "../request-logger-z3FaJPry.js";
|
|
2
2
|
export { RequestLoggerOptions, makeRequestLogger };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "../logger-
|
|
2
|
-
import { n as StructuredLogger, r as makeStructuredLogger, t as LogLevel } from "../structured-logger-DyrZwR3S.js";
|
|
1
|
+
import { n as StructuredLogger, r as makeStructuredLogger, t as LogLevel } from "../structured-logger-DJJ-0mnW.js";
|
|
3
2
|
export { LogLevel, StructuredLogger, makeStructuredLogger };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "../db-
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../
|
|
9
|
-
import { t as registerCoreModule } from "../core.module-_mfoxc8b.js";
|
|
1
|
+
import "../db-Brm6l10l.js";
|
|
2
|
+
import "../error-handler-Up4XIzWt.js";
|
|
3
|
+
import "../index-DXJbbtWQ.js";
|
|
4
|
+
import "../structured-logger-DJJ-0mnW.js";
|
|
5
|
+
import "../request-logger-z3FaJPry.js";
|
|
6
|
+
import "../index-CuY8tqBC.js";
|
|
7
|
+
import "../types-BDBUcrxL.js";
|
|
8
|
+
import { t as registerCoreModule } from "../core.module-BEuDFLDA.js";
|
|
10
9
|
export { registerCoreModule };
|
|
@@ -2,12 +2,11 @@ import "../db-C4IcCT04.js";
|
|
|
2
2
|
import "../structured-logger-BsxDI9zX.js";
|
|
3
3
|
import "../request-logger-Cw1XQWTV.js";
|
|
4
4
|
import "../logging-4mLSrMc6.js";
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../in-memory-
|
|
9
|
-
import "../in-memory-
|
|
10
|
-
import "../
|
|
11
|
-
import { t as registerCoreModule } from "../core.module-ehJ0bdNr.js";
|
|
5
|
+
import "../error-handler-B4kyoFfy.js";
|
|
6
|
+
import "../errors-DXbNwomE.js";
|
|
7
|
+
import "../in-memory-event-bus-D0n7i3uf.js";
|
|
8
|
+
import "../in-memory-cache-store-C-v4ag_e.js";
|
|
9
|
+
import "../in-memory-rate-limiter-ClGoFbk6.js";
|
|
10
|
+
import { t as registerCoreModule } from "../core.module-oSFmg8ER.js";
|
|
12
11
|
|
|
13
12
|
export { registerCoreModule };
|
package/dist/modules/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import "../db-
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import {
|
|
9
|
-
import { t as
|
|
10
|
-
import
|
|
11
|
-
import "../index-B7z6dpFd.js";
|
|
1
|
+
import "../db-Brm6l10l.js";
|
|
2
|
+
import "../error-handler-Up4XIzWt.js";
|
|
3
|
+
import "../index-DXJbbtWQ.js";
|
|
4
|
+
import "../structured-logger-DJJ-0mnW.js";
|
|
5
|
+
import "../request-logger-z3FaJPry.js";
|
|
6
|
+
import "../index-CuY8tqBC.js";
|
|
7
|
+
import { n as Cradle, t as Config } from "../types-BDBUcrxL.js";
|
|
8
|
+
import { t as registerCoreModule } from "../core.module-BEuDFLDA.js";
|
|
9
|
+
import { t as registerUserModule } from "../user.module-DWDd3hGF.js";
|
|
10
|
+
import "../index-Cg5cFzs-.js";
|
|
12
11
|
export { Config, Cradle, registerCoreModule, registerUserModule };
|
package/dist/modules/index.js
CHANGED
|
@@ -3,14 +3,13 @@ import "../user.drizzle-CgKIqqb3.js";
|
|
|
3
3
|
import "../structured-logger-BsxDI9zX.js";
|
|
4
4
|
import "../request-logger-Cw1XQWTV.js";
|
|
5
5
|
import "../logging-4mLSrMc6.js";
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../
|
|
9
|
-
import "../in-memory-
|
|
10
|
-
import "../in-memory-
|
|
11
|
-
import "../
|
|
12
|
-
import { t as
|
|
13
|
-
import
|
|
14
|
-
import "../modules-C_2SF3he.js";
|
|
6
|
+
import "../error-handler-B4kyoFfy.js";
|
|
7
|
+
import "../errors-DXbNwomE.js";
|
|
8
|
+
import "../in-memory-event-bus-D0n7i3uf.js";
|
|
9
|
+
import "../in-memory-cache-store-C-v4ag_e.js";
|
|
10
|
+
import "../in-memory-rate-limiter-ClGoFbk6.js";
|
|
11
|
+
import { t as registerCoreModule } from "../core.module-oSFmg8ER.js";
|
|
12
|
+
import { t as registerUserModule } from "../user.module-iUC-HTqT.js";
|
|
13
|
+
import "../modules-BICEbyjm.js";
|
|
15
14
|
|
|
16
15
|
export { registerCoreModule, registerUserModule };
|
package/dist/modules/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import "../db-
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import { n as Cradle, t as Config } from "../types-BnE7rffD.js";
|
|
1
|
+
import "../db-Brm6l10l.js";
|
|
2
|
+
import "../error-handler-Up4XIzWt.js";
|
|
3
|
+
import "../index-DXJbbtWQ.js";
|
|
4
|
+
import "../structured-logger-DJJ-0mnW.js";
|
|
5
|
+
import "../request-logger-z3FaJPry.js";
|
|
6
|
+
import "../index-CuY8tqBC.js";
|
|
7
|
+
import { n as Cradle, t as Config } from "../types-BDBUcrxL.js";
|
|
9
8
|
export { Config, Cradle };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "../db-
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../
|
|
9
|
-
import { t as registerUserModule } from "../user.module-DqTfy_MM.js";
|
|
1
|
+
import "../db-Brm6l10l.js";
|
|
2
|
+
import "../error-handler-Up4XIzWt.js";
|
|
3
|
+
import "../index-DXJbbtWQ.js";
|
|
4
|
+
import "../structured-logger-DJJ-0mnW.js";
|
|
5
|
+
import "../request-logger-z3FaJPry.js";
|
|
6
|
+
import "../index-CuY8tqBC.js";
|
|
7
|
+
import "../types-BDBUcrxL.js";
|
|
8
|
+
import { t as registerUserModule } from "../user.module-DWDd3hGF.js";
|
|
10
9
|
export { registerUserModule };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-
|
|
1
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-DjyLAj3S.js";
|
|
2
2
|
export { InMemoryRateLimiterStore, makeInMemoryRateLimiterStore };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-
|
|
1
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-ClGoFbk6.js";
|
|
2
2
|
|
|
3
3
|
export { InMemoryRateLimiterStore, makeInMemoryRateLimiterStore };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-
|
|
2
|
-
import { t as RateLimiterStore } from "../index-
|
|
1
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-DjyLAj3S.js";
|
|
2
|
+
import { t as RateLimiterStore } from "../index-B8lmalaK.js";
|
|
3
3
|
export { InMemoryRateLimiterStore, RateLimiterStore, makeInMemoryRateLimiterStore };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-
|
|
2
|
-
import "../rate-limiter-
|
|
1
|
+
import { n as makeInMemoryRateLimiterStore, t as InMemoryRateLimiterStore } from "../in-memory-rate-limiter-ClGoFbk6.js";
|
|
2
|
+
import "../rate-limiter-DhcBdNmF.js";
|
|
3
3
|
|
|
4
4
|
export { InMemoryRateLimiterStore, makeInMemoryRateLimiterStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-logger-Cw1XQWTV.js","names":["context: LogContext"],"sources":["../src/logging/request-logger.ts"],"sourcesContent":["import type { Logger, LogContext } from '@kuckit/domain
|
|
1
|
+
{"version":3,"file":"request-logger-Cw1XQWTV.js","names":["context: LogContext"],"sources":["../src/logging/request-logger.ts"],"sourcesContent":["import type { Logger, LogContext } from '@kuckit/domain'\n\n/**\n * Options for creating a request-scoped logger\n */\nexport interface RequestLoggerOptions {\n\trequestId: string\n\tuserId?: string\n\tbaseLogger: Logger\n}\n\n/**\n * Create a request-scoped logger that automatically includes\n * requestId and userId in all log entries.\n *\n * This wraps the base singleton logger and enriches all log\n * calls with request context for Loki-compatible structured logging.\n */\nexport const makeRequestLogger = (options: RequestLoggerOptions): Logger => {\n\tconst context: LogContext = {\n\t\trequestId: options.requestId,\n\t\t...(options.userId && { userId: options.userId }),\n\t}\n\n\treturn {\n\t\tdebug: (message: string, meta?: LogContext) => {\n\t\t\toptions.baseLogger.debug(message, { ...context, ...meta })\n\t\t},\n\n\t\tinfo: (message: string, meta?: LogContext) => {\n\t\t\toptions.baseLogger.info(message, { ...context, ...meta })\n\t\t},\n\n\t\twarn: (message: string, meta?: LogContext) => {\n\t\t\toptions.baseLogger.warn(message, { ...context, ...meta })\n\t\t},\n\n\t\terror: (message: string, meta?: LogContext | Error) => {\n\t\t\tif (meta instanceof Error) {\n\t\t\t\toptions.baseLogger.error(message, {\n\t\t\t\t\t...context,\n\t\t\t\t\terror: meta.message,\n\t\t\t\t\tstack: meta.stack,\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\toptions.baseLogger.error(message, { ...context, ...meta })\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,qBAAqB,YAA0C;CAC3E,MAAMA,UAAsB;EAC3B,WAAW,QAAQ;EACnB,GAAI,QAAQ,UAAU,EAAE,QAAQ,QAAQ,QAAQ;EAChD;AAED,QAAO;EACN,QAAQ,SAAiB,SAAsB;AAC9C,WAAQ,WAAW,MAAM,SAAS;IAAE,GAAG;IAAS,GAAG;IAAM,CAAC;;EAG3D,OAAO,SAAiB,SAAsB;AAC7C,WAAQ,WAAW,KAAK,SAAS;IAAE,GAAG;IAAS,GAAG;IAAM,CAAC;;EAG1D,OAAO,SAAiB,SAAsB;AAC7C,WAAQ,WAAW,KAAK,SAAS;IAAE,GAAG;IAAS,GAAG;IAAM,CAAC;;EAG1D,QAAQ,SAAiB,SAA8B;AACtD,OAAI,gBAAgB,MACnB,SAAQ,WAAW,MAAM,SAAS;IACjC,GAAG;IACH,OAAO,KAAK;IACZ,OAAO,KAAK;IACZ,CAAC;OAEF,SAAQ,WAAW,MAAM,SAAS;IAAE,GAAG;IAAS,GAAG;IAAM,CAAC;;EAG5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from "@kuckit/domain
|
|
1
|
+
import { Logger } from "@kuckit/domain";
|
|
2
2
|
|
|
3
3
|
//#region src/logging/request-logger.d.ts
|
|
4
4
|
|
|
@@ -20,4 +20,4 @@ interface RequestLoggerOptions {
|
|
|
20
20
|
declare const makeRequestLogger: (options: RequestLoggerOptions) => Logger;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { makeRequestLogger as n, RequestLoggerOptions as t };
|
|
23
|
-
//# sourceMappingURL=request-logger-
|
|
23
|
+
//# sourceMappingURL=request-logger-z3FaJPry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-logger-BsxDI9zX.js","names":["options: {\n\t\t\tlogDir?: string\n\t\t\tenableFile?: boolean\n\t\t\tminLevel?: LogLevel\n\t\t}","levels: LogLevel[]","logObject: Record<string, unknown>","lines: string[]"],"sources":["../src/logging/structured-logger.ts"],"sourcesContent":["import { createWriteStream, existsSync, mkdirSync } from 'fs'\nimport path from 'path'\nimport type { Logger, LogContext } from '
|
|
1
|
+
{"version":3,"file":"structured-logger-BsxDI9zX.js","names":["options: {\n\t\t\tlogDir?: string\n\t\t\tenableFile?: boolean\n\t\t\tminLevel?: LogLevel\n\t\t}","levels: LogLevel[]","logObject: Record<string, unknown>","lines: string[]"],"sources":["../src/logging/structured-logger.ts"],"sourcesContent":["import { createWriteStream, existsSync, mkdirSync } from 'fs'\nimport path from 'path'\nimport type { Logger, LogContext } from '@kuckit/domain'\n\nexport type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'\n\n/**\n * Structured logger implementation\n * - JSON logs compatible with Loki\n * - File + stdout support\n * - Prometheus metrics collection\n */\nexport class StructuredLogger implements Logger {\n\tprivate fileStream: ReturnType<typeof createWriteStream> | null = null\n\tprivate metrics: MetricsCollector\n\n\tconstructor(\n\t\tprivate options: {\n\t\t\tlogDir?: string\n\t\t\tenableFile?: boolean\n\t\t\tminLevel?: LogLevel\n\t\t} = {}\n\t) {\n\t\tthis.metrics = new MetricsCollector()\n\n\t\tif (options.enableFile && options.logDir) {\n\t\t\tthis.initFileStream(options.logDir)\n\t\t}\n\t}\n\n\tprivate initFileStream(logDir: string): void {\n\t\tif (!existsSync(logDir)) {\n\t\t\tmkdirSync(logDir, { recursive: true })\n\t\t}\n\n\t\tconst logFile = path.join(logDir, `app-${new Date().toISOString().split('T')[0]}.log`)\n\t\tthis.fileStream = createWriteStream(logFile, { flags: 'a' })\n\t}\n\n\tdebug(message: string, meta?: LogContext): void {\n\t\tthis.log('DEBUG', message, meta)\n\t}\n\n\tinfo(message: string, meta?: LogContext): void {\n\t\tthis.log('INFO', message, meta)\n\t}\n\n\twarn(message: string, meta?: LogContext): void {\n\t\tthis.log('WARN', message, meta)\n\t}\n\n\terror(message: string, meta?: LogContext | Error): void {\n\t\tconst context = meta instanceof Error ? { error: meta.message, stack: meta.stack } : meta\n\t\tthis.log('ERROR', message, context)\n\t}\n\n\tprivate log(level: LogLevel, message: string, meta?: LogContext): void {\n\t\tif (this.shouldSkip(level)) return\n\n\t\tconst timestamp = new Date().toISOString()\n\t\tconst logEntry = this.formatLog(level, message, meta, timestamp)\n\n\t\t// stdout\n\t\tconsole.log(logEntry)\n\n\t\t// file\n\t\tif (this.fileStream) {\n\t\t\tthis.fileStream.write(logEntry + '\\n')\n\t\t}\n\n\t\t// metrics\n\t\tthis.metrics.recordLog(level, meta?.feature)\n\t}\n\n\tprivate shouldSkip(level: LogLevel): boolean {\n\t\tconst levels: LogLevel[] = ['DEBUG', 'INFO', 'WARN', 'ERROR']\n\t\tconst minLevel = this.options.minLevel || 'DEBUG'\n\t\treturn levels.indexOf(level) < levels.indexOf(minLevel)\n\t}\n\n\tprivate formatLog(\n\t\tlevel: LogLevel,\n\t\tmessage: string,\n\t\tmeta: LogContext | undefined,\n\t\ttimestamp: string\n\t): string {\n\t\tconst logObject: Record<string, unknown> = {\n\t\t\ttimestamp,\n\t\t\tlevel,\n\t\t\tmessage,\n\t\t\t...meta,\n\t\t}\n\n\t\t// Loki labels (structured fields at root level)\n\t\tif (meta?.requestId) logObject.requestId = meta.requestId\n\t\tif (meta?.userId) logObject.userId = meta.userId\n\t\tif (meta?.feature) logObject.feature = meta.feature\n\n\t\treturn JSON.stringify(logObject)\n\t}\n\n\t/**\n\t * Get metrics in Prometheus text format\n\t */\n\tgetMetrics(): string {\n\t\treturn this.metrics.toPrometheusFormat()\n\t}\n\n\t/**\n\t * Cleanup resources\n\t */\n\tasync dispose(): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tif (this.fileStream) {\n\t\t\t\tthis.fileStream.end(() => resolve())\n\t\t\t} else {\n\t\t\t\tresolve()\n\t\t\t}\n\t\t})\n\t}\n}\n\n/**\n * Prometheus metrics collector\n */\nclass MetricsCollector {\n\tprivate logCount: Map<LogLevel, number> = new Map([\n\t\t['DEBUG', 0],\n\t\t['INFO', 0],\n\t\t['WARN', 0],\n\t\t['ERROR', 0],\n\t])\n\tprivate featureCount: Map<string, number> = new Map()\n\n\trecordLog(level: LogLevel, feature?: string): void {\n\t\tthis.logCount.set(level, (this.logCount.get(level) || 0) + 1)\n\t\tif (feature) {\n\t\t\tthis.featureCount.set(feature, (this.featureCount.get(feature) || 0) + 1)\n\t\t}\n\t}\n\n\ttoPrometheusFormat(): string {\n\t\tconst lines: string[] = [\n\t\t\t'# HELP app_logs_total Total number of logs by level',\n\t\t\t'# TYPE app_logs_total counter',\n\t\t]\n\n\t\t// Log counters by level\n\t\tfor (const [level, count] of this.logCount) {\n\t\t\tlines.push(`app_logs_total{level=\"${level}\"} ${count}`)\n\t\t}\n\n\t\tlines.push('')\n\t\tlines.push('# HELP app_feature_logs_total Total logs by feature')\n\t\tlines.push('# TYPE app_feature_logs_total counter')\n\n\t\t// Log counters by feature\n\t\tfor (const [feature, count] of this.featureCount) {\n\t\t\tlines.push(`app_feature_logs_total{feature=\"${feature}\"} ${count}`)\n\t\t}\n\n\t\treturn lines.join('\\n')\n\t}\n}\n\n/**\n * Create logger instance\n */\nexport const makeStructuredLogger = (options?: {\n\tlogDir?: string\n\tenableFile?: boolean\n\tminLevel?: LogLevel\n}): StructuredLogger => {\n\treturn new StructuredLogger(options)\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAa,mBAAb,MAAgD;CAC/C,AAAQ,aAA0D;CAClE,AAAQ;CAER,YACC,AAAQA,UAIJ,EAAE,EACL;EALO;AAMR,OAAK,UAAU,IAAI,kBAAkB;AAErC,MAAI,QAAQ,cAAc,QAAQ,OACjC,MAAK,eAAe,QAAQ,OAAO;;CAIrC,AAAQ,eAAe,QAAsB;AAC5C,MAAI,CAAC,WAAW,OAAO,CACtB,WAAU,QAAQ,EAAE,WAAW,MAAM,CAAC;AAIvC,OAAK,aAAa,kBADF,KAAK,KAAK,QAAQ,wBAAO,IAAI,MAAM,EAAC,aAAa,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,EACzC,EAAE,OAAO,KAAK,CAAC;;CAG7D,MAAM,SAAiB,MAAyB;AAC/C,OAAK,IAAI,SAAS,SAAS,KAAK;;CAGjC,KAAK,SAAiB,MAAyB;AAC9C,OAAK,IAAI,QAAQ,SAAS,KAAK;;CAGhC,KAAK,SAAiB,MAAyB;AAC9C,OAAK,IAAI,QAAQ,SAAS,KAAK;;CAGhC,MAAM,SAAiB,MAAiC;EACvD,MAAM,UAAU,gBAAgB,QAAQ;GAAE,OAAO,KAAK;GAAS,OAAO,KAAK;GAAO,GAAG;AACrF,OAAK,IAAI,SAAS,SAAS,QAAQ;;CAGpC,AAAQ,IAAI,OAAiB,SAAiB,MAAyB;AACtE,MAAI,KAAK,WAAW,MAAM,CAAE;EAE5B,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;EAC1C,MAAM,WAAW,KAAK,UAAU,OAAO,SAAS,MAAM,UAAU;AAGhE,UAAQ,IAAI,SAAS;AAGrB,MAAI,KAAK,WACR,MAAK,WAAW,MAAM,WAAW,KAAK;AAIvC,OAAK,QAAQ,UAAU,OAAO,MAAM,QAAQ;;CAG7C,AAAQ,WAAW,OAA0B;EAC5C,MAAMC,SAAqB;GAAC;GAAS;GAAQ;GAAQ;GAAQ;EAC7D,MAAM,WAAW,KAAK,QAAQ,YAAY;AAC1C,SAAO,OAAO,QAAQ,MAAM,GAAG,OAAO,QAAQ,SAAS;;CAGxD,AAAQ,UACP,OACA,SACA,MACA,WACS;EACT,MAAMC,YAAqC;GAC1C;GACA;GACA;GACA,GAAG;GACH;AAGD,MAAI,MAAM,UAAW,WAAU,YAAY,KAAK;AAChD,MAAI,MAAM,OAAQ,WAAU,SAAS,KAAK;AAC1C,MAAI,MAAM,QAAS,WAAU,UAAU,KAAK;AAE5C,SAAO,KAAK,UAAU,UAAU;;;;;CAMjC,aAAqB;AACpB,SAAO,KAAK,QAAQ,oBAAoB;;;;;CAMzC,MAAM,UAAyB;AAC9B,SAAO,IAAI,SAAS,YAAY;AAC/B,OAAI,KAAK,WACR,MAAK,WAAW,UAAU,SAAS,CAAC;OAEpC,UAAS;IAET;;;;;;AAOJ,IAAM,mBAAN,MAAuB;CACtB,AAAQ,WAAkC,IAAI,IAAI;EACjD,CAAC,SAAS,EAAE;EACZ,CAAC,QAAQ,EAAE;EACX,CAAC,QAAQ,EAAE;EACX,CAAC,SAAS,EAAE;EACZ,CAAC;CACF,AAAQ,+BAAoC,IAAI,KAAK;CAErD,UAAU,OAAiB,SAAwB;AAClD,OAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,IAAI,KAAK,EAAE;AAC7D,MAAI,QACH,MAAK,aAAa,IAAI,UAAU,KAAK,aAAa,IAAI,QAAQ,IAAI,KAAK,EAAE;;CAI3E,qBAA6B;EAC5B,MAAMC,QAAkB,CACvB,uDACA,gCACA;AAGD,OAAK,MAAM,CAAC,OAAO,UAAU,KAAK,SACjC,OAAM,KAAK,yBAAyB,MAAM,KAAK,QAAQ;AAGxD,QAAM,KAAK,GAAG;AACd,QAAM,KAAK,sDAAsD;AACjE,QAAM,KAAK,wCAAwC;AAGnD,OAAK,MAAM,CAAC,SAAS,UAAU,KAAK,aACnC,OAAM,KAAK,mCAAmC,QAAQ,KAAK,QAAQ;AAGpE,SAAO,MAAM,KAAK,KAAK;;;;;;AAOzB,MAAa,wBAAwB,YAIb;AACvB,QAAO,IAAI,iBAAiB,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogContext, Logger } from "@kuckit/domain";
|
|
2
2
|
|
|
3
3
|
//#region src/logging/structured-logger.d.ts
|
|
4
4
|
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
@@ -44,4 +44,4 @@ declare const makeStructuredLogger: (options?: {
|
|
|
44
44
|
}) => StructuredLogger;
|
|
45
45
|
//#endregion
|
|
46
46
|
export { StructuredLogger as n, makeStructuredLogger as r, LogLevel as t };
|
|
47
|
-
//# sourceMappingURL=structured-logger-
|
|
47
|
+
//# sourceMappingURL=structured-logger-DJJ-0mnW.d.ts.map
|
|
@@ -19,4 +19,4 @@ declare const runInTransaction: <T>(container: AwilixContainer, fn: (txScope: Aw
|
|
|
19
19
|
type TransactionFn<T> = (txScope: AwilixContainer) => Promise<T>;
|
|
20
20
|
//#endregion
|
|
21
21
|
export { runInTransaction as n, TransactionFn as t };
|
|
22
|
-
//# sourceMappingURL=transaction-
|
|
22
|
+
//# sourceMappingURL=transaction-D961784D.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createDb } from "./db-
|
|
2
|
-
import { t as ErrorHandler } from "./error-handler-
|
|
3
|
-
import { n as StructuredLogger } from "./structured-logger-
|
|
1
|
+
import { t as createDb } from "./db-Brm6l10l.js";
|
|
2
|
+
import { t as ErrorHandler } from "./error-handler-Up4XIzWt.js";
|
|
3
|
+
import { n as StructuredLogger } from "./structured-logger-DJJ-0mnW.js";
|
|
4
4
|
import { Pool } from "pg";
|
|
5
5
|
import { CacheStore, Clock, EventBus, EventPublisher, Logger, RateLimiterStore, User, UserRepository } from "@kuckit/domain";
|
|
6
6
|
import { google } from "@ai-sdk/google";
|
|
@@ -63,4 +63,4 @@ interface Cradle {
|
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
65
|
export { Cradle as n, Config as t };
|
|
66
|
-
//# sourceMappingURL=types-
|
|
66
|
+
//# sourceMappingURL=types-BDBUcrxL.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from "@kuckit/domain";
|
|
2
2
|
|
|
3
3
|
//#region src/decorators/use-case-decorator.d.ts
|
|
4
4
|
|
|
@@ -49,4 +49,4 @@ declare const decorateUseCase: <T extends (...args: any[]) => Promise<any>>(useC
|
|
|
49
49
|
declare const makeDecoratedUseCase: <T extends (...args: any[]) => Promise<any>>(useCase: T, context: DecoratorContext, featureName: string) => T;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { makeDecoratedUseCase as a, withRequestTracing as c, decorateUseCase as i, PerformanceMetrics as n, withErrorHandling as o, UseCase as r, withPerformanceMonitoring as s, DecoratorContext as t };
|
|
52
|
-
//# sourceMappingURL=use-case-decorator-
|
|
52
|
+
//# sourceMappingURL=use-case-decorator-D9fX_4EY.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppError } from "@kuckit/domain";
|
|
2
2
|
|
|
3
3
|
//#region src/decorators/use-case-decorator.ts
|
|
4
4
|
/**
|
|
@@ -115,4 +115,4 @@ const makeDecoratedUseCase = (useCase, context, featureName) => {
|
|
|
115
115
|
|
|
116
116
|
//#endregion
|
|
117
117
|
export { withRequestTracing as a, withPerformanceMonitoring as i, makeDecoratedUseCase as n, withErrorHandling as r, decorateUseCase as t };
|
|
118
|
-
//# sourceMappingURL=use-case-decorator-
|
|
118
|
+
//# sourceMappingURL=use-case-decorator-DRIN79Vt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-case-decorator-DRIN79Vt.js","names":[],"sources":["../src/decorators/use-case-decorator.ts"],"sourcesContent":["import type { Logger } from '@kuckit/domain'\nimport { AppError } from '@kuckit/domain'\n\n/**\n * Use case decorator type\n * Wraps a use case function with cross-cutting concerns\n */\nexport type UseCase<T extends (...args: any[]) => Promise<any>> = T\n\n/**\n * Decorator context passed to all decorators\n */\nexport interface DecoratorContext {\n\tlogger: Logger\n\trequestId?: string\n\tuserId?: string\n\tfeature?: string\n}\n\n/**\n * Performance metrics collected by decorator\n */\nexport interface PerformanceMetrics {\n\tstartTime: number\n\tendTime: number\n\tdurationMs: number\n}\n\n/**\n * Base decorator that adds performance monitoring\n */\nexport const withPerformanceMonitoring = <T extends (...args: any[]) => Promise<any>>(\n\tuseCase: T,\n\tcontext: DecoratorContext,\n\tfeatureName: string\n): T => {\n\treturn (async (...args: Parameters<T>) => {\n\t\tconst startTime = Date.now()\n\n\t\ttry {\n\t\t\tconst result = await useCase(...args)\n\t\t\tconst durationMs = Date.now() - startTime\n\n\t\t\tcontext.logger.debug(`${featureName}_completed`, {\n\t\t\t\trequestId: context.requestId,\n\t\t\t\tfeature: featureName,\n\t\t\t\tdurationMs,\n\t\t\t})\n\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\tconst durationMs = Date.now() - startTime\n\n\t\t\t// Log even errors with timing\n\t\t\tif (error instanceof AppError) {\n\t\t\t\tcontext.logger.debug(`${featureName}_error`, {\n\t\t\t\t\trequestId: context.requestId,\n\t\t\t\t\tfeature: featureName,\n\t\t\t\t\tdurationMs,\n\t\t\t\t\tcode: error.code,\n\t\t\t\t\tseverity: error.severity,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tthrow error\n\t\t}\n\t}) as T\n}\n\n/**\n * Base decorator that adds error handling and conversion\n */\nexport const withErrorHandling = <T extends (...args: any[]) => Promise<any>>(\n\tuseCase: T,\n\tcontext: DecoratorContext,\n\tfeatureName: string\n): T => {\n\treturn (async (...args: Parameters<T>) => {\n\t\ttry {\n\t\t\treturn await useCase(...args)\n\t\t} catch (error) {\n\t\t\t// AppErrors pass through (already have proper structure)\n\t\t\tif (error instanceof AppError) {\n\t\t\t\tthrow error\n\t\t\t}\n\n\t\t\t// Wrap unexpected errors\n\t\t\tif (error instanceof Error) {\n\t\t\t\tcontext.logger.error(`${featureName}_unexpected_error`, {\n\t\t\t\t\trequestId: context.requestId,\n\t\t\t\t\tfeature: featureName,\n\t\t\t\t\terrorName: error.name,\n\t\t\t\t\terrorMessage: error.message,\n\t\t\t\t\tstack: error.stack,\n\t\t\t\t})\n\n\t\t\t\tthrow new AppError('INTERNAL_SERVER_ERROR' as any, `Unexpected error in ${featureName}`, {\n\t\t\t\t\tstatusCode: 500,\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\toriginalError: error.message,\n\t\t\t\t\t\tfeature: featureName,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\n\t\t\t// Unknown errors\n\t\t\tcontext.logger.error(`${featureName}_unknown_error`, {\n\t\t\t\trequestId: context.requestId,\n\t\t\t\tfeature: featureName,\n\t\t\t})\n\n\t\t\tthrow new AppError('INTERNAL_SERVER_ERROR' as any, `Unknown error in ${featureName}`, {\n\t\t\t\tstatusCode: 500,\n\t\t\t\tmeta: { feature: featureName },\n\t\t\t})\n\t\t}\n\t}) as T\n}\n\n/**\n * Request tracing decorator - adds context to logs\n */\nexport const withRequestTracing = <T extends (...args: any[]) => Promise<any>>(\n\tuseCase: T,\n\tcontext: DecoratorContext,\n\tfeatureName: string\n): T => {\n\treturn (async (...args: Parameters<T>) => {\n\t\tcontext.logger.info(`${featureName}_started`, {\n\t\t\trequestId: context.requestId,\n\t\t\tuserId: context.userId,\n\t\t\tfeature: featureName,\n\t\t})\n\n\t\ttry {\n\t\t\tconst result = await useCase(...args)\n\n\t\t\tcontext.logger.info(`${featureName}_success`, {\n\t\t\t\trequestId: context.requestId,\n\t\t\t\tuserId: context.userId,\n\t\t\t\tfeature: featureName,\n\t\t\t})\n\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\tcontext.logger.error(`${featureName}_failed`, {\n\t\t\t\trequestId: context.requestId,\n\t\t\t\tuserId: context.userId,\n\t\t\t\tfeature: featureName,\n\t\t\t\terror: error instanceof Error ? error.message : 'Unknown error',\n\t\t\t})\n\n\t\t\tthrow error\n\t\t}\n\t}) as T\n}\n\n/**\n * Compose multiple decorators together\n * Order: Tracing → Performance → Error Handling\n * (outermost → innermost)\n */\nexport const decorateUseCase = <T extends (...args: any[]) => Promise<any>>(\n\tuseCase: T,\n\tcontext: DecoratorContext,\n\tfeatureName: string\n): T => {\n\t// Apply decorators from outermost to innermost\n\t// Error handling (innermost - catches first)\n\tlet decorated = withErrorHandling(useCase, context, featureName)\n\n\t// Performance monitoring (middle - wraps error handling)\n\tdecorated = withPerformanceMonitoring(decorated, context, featureName)\n\n\t// Request tracing (outermost - visible in logs)\n\tdecorated = withRequestTracing(decorated, context, featureName)\n\n\treturn decorated\n}\n\n/**\n * Factory for creating decorated use cases\n * Used in dependency injection to wrap use cases automatically\n */\nexport const makeDecoratedUseCase = <T extends (...args: any[]) => Promise<any>>(\n\tuseCase: T,\n\tcontext: DecoratorContext,\n\tfeatureName: string\n): T => {\n\treturn decorateUseCase(useCase, context, featureName)\n}\n"],"mappings":";;;;;;AA+BA,MAAa,6BACZ,SACA,SACA,gBACO;AACP,SAAQ,OAAO,GAAG,SAAwB;EACzC,MAAM,YAAY,KAAK,KAAK;AAE5B,MAAI;GACH,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK;GACrC,MAAM,aAAa,KAAK,KAAK,GAAG;AAEhC,WAAQ,OAAO,MAAM,GAAG,YAAY,aAAa;IAChD,WAAW,QAAQ;IACnB,SAAS;IACT;IACA,CAAC;AAEF,UAAO;WACC,OAAO;GACf,MAAM,aAAa,KAAK,KAAK,GAAG;AAGhC,OAAI,iBAAiB,SACpB,SAAQ,OAAO,MAAM,GAAG,YAAY,SAAS;IAC5C,WAAW,QAAQ;IACnB,SAAS;IACT;IACA,MAAM,MAAM;IACZ,UAAU,MAAM;IAChB,CAAC;AAGH,SAAM;;;;;;;AAQT,MAAa,qBACZ,SACA,SACA,gBACO;AACP,SAAQ,OAAO,GAAG,SAAwB;AACzC,MAAI;AACH,UAAO,MAAM,QAAQ,GAAG,KAAK;WACrB,OAAO;AAEf,OAAI,iBAAiB,SACpB,OAAM;AAIP,OAAI,iBAAiB,OAAO;AAC3B,YAAQ,OAAO,MAAM,GAAG,YAAY,oBAAoB;KACvD,WAAW,QAAQ;KACnB,SAAS;KACT,WAAW,MAAM;KACjB,cAAc,MAAM;KACpB,OAAO,MAAM;KACb,CAAC;AAEF,UAAM,IAAI,SAAS,yBAAgC,uBAAuB,eAAe;KACxF,YAAY;KACZ,MAAM;MACL,eAAe,MAAM;MACrB,SAAS;MACT;KACD,CAAC;;AAIH,WAAQ,OAAO,MAAM,GAAG,YAAY,iBAAiB;IACpD,WAAW,QAAQ;IACnB,SAAS;IACT,CAAC;AAEF,SAAM,IAAI,SAAS,yBAAgC,oBAAoB,eAAe;IACrF,YAAY;IACZ,MAAM,EAAE,SAAS,aAAa;IAC9B,CAAC;;;;;;;AAQL,MAAa,sBACZ,SACA,SACA,gBACO;AACP,SAAQ,OAAO,GAAG,SAAwB;AACzC,UAAQ,OAAO,KAAK,GAAG,YAAY,WAAW;GAC7C,WAAW,QAAQ;GACnB,QAAQ,QAAQ;GAChB,SAAS;GACT,CAAC;AAEF,MAAI;GACH,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK;AAErC,WAAQ,OAAO,KAAK,GAAG,YAAY,WAAW;IAC7C,WAAW,QAAQ;IACnB,QAAQ,QAAQ;IAChB,SAAS;IACT,CAAC;AAEF,UAAO;WACC,OAAO;AACf,WAAQ,OAAO,MAAM,GAAG,YAAY,UAAU;IAC7C,WAAW,QAAQ;IACnB,QAAQ,QAAQ;IAChB,SAAS;IACT,OAAO,iBAAiB,QAAQ,MAAM,UAAU;IAChD,CAAC;AAEF,SAAM;;;;;;;;;AAUT,MAAa,mBACZ,SACA,SACA,gBACO;CAGP,IAAI,YAAY,kBAAkB,SAAS,SAAS,YAAY;AAGhE,aAAY,0BAA0B,WAAW,SAAS,YAAY;AAGtE,aAAY,mBAAmB,WAAW,SAAS,YAAY;AAE/D,QAAO;;;;;;AAOR,MAAa,wBACZ,SACA,SACA,gBACO;AACP,QAAO,gBAAgB,SAAS,SAAS,YAAY"}
|
|
@@ -9,4 +9,4 @@ import { UserRepository } from "@kuckit/domain/ports/user-repository";
|
|
|
9
9
|
declare const makeDrizzleUserRepository: (db: NodePgDatabase) => UserRepository;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { makeDrizzleUserRepository as t };
|
|
12
|
-
//# sourceMappingURL=user.drizzle-
|
|
12
|
+
//# sourceMappingURL=user.drizzle-SbUroSiT.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Cradle } from "./types-
|
|
1
|
+
import { n as Cradle } from "./types-BDBUcrxL.js";
|
|
2
2
|
import { AwilixContainer } from "awilix";
|
|
3
3
|
|
|
4
4
|
//#region src/modules/user.module.d.ts
|
|
@@ -12,4 +12,4 @@ import { AwilixContainer } from "awilix";
|
|
|
12
12
|
declare const registerUserModule: (container: AwilixContainer<Cradle>) => void;
|
|
13
13
|
//#endregion
|
|
14
14
|
export { registerUserModule as t };
|
|
15
|
-
//# sourceMappingURL=user.module-
|
|
15
|
+
//# sourceMappingURL=user.module-DWDd3hGF.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.module-
|
|
1
|
+
{"version":3,"file":"user.module-iUC-HTqT.js","names":[],"sources":["../src/modules/user.module.ts"],"sourcesContent":["import { asFunction, type AwilixContainer } from 'awilix'\nimport { makeDrizzleUserRepository } from '../db/drizzle/repositories/user.drizzle'\nimport type { Cradle } from './types'\n\n/**\n * User repository module: registers user-related repositories\n *\n * Note: Use case registrations are in apps/server/src/modules/user.module.ts\n * to maintain Clean Architecture layering (Infrastructure should not import Application)\n */\nexport const registerUserModule = (container: AwilixContainer<Cradle>): void => {\n\tcontainer.register({\n\t\tuserRepository: asFunction(({ db }) => makeDrizzleUserRepository(db)).scoped(),\n\t})\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAa,sBAAsB,cAA6C;AAC/E,WAAU,SAAS,EAClB,gBAAgB,YAAY,EAAE,SAAS,0BAA0B,GAAG,CAAC,CAAC,QAAQ,EAC9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-caching-
|
|
1
|
+
{"version":3,"file":"with-caching-DjOW2Xjh.js","names":["cached"],"sources":["../src/decorators/with-caching.ts"],"sourcesContent":["import type { CacheStore } from '@kuckit/domain'\n\n/**\n * Options for caching decorator\n */\nexport interface WithCachingOptions {\n\t/** Cache key function - maps input to cache key */\n\tkeyFn: (input: any) => string\n\t/** Time to live in milliseconds */\n\tttlMs: number\n\t/** Stale-while-revalidate: return stale value while refreshing in background */\n\tstaleWhileRevalidateMs?: number\n}\n\n/**\n * Wraps a use case with caching\n * - Only works with idempotent read operations\n * - Key function determines cache key from input\n * - TTL controls cache expiration\n * - SWR allows returning stale value while revalidating\n *\n * @example\n * ```ts\n * const cachedGetUser = withCaching(\n * getUserProfile,\n * cacheStore,\n * {\n * keyFn: (input) => `user:${input.userId}`,\n * ttlMs: 60000, // 1 minute\n * staleWhileRevalidateMs: 120000, // 2 minutes\n * }\n * )\n * ```\n */\nexport const withCaching = <I extends Record<string, any>, O>(\n\tfn: (input: I) => Promise<O>,\n\tcacheStore: CacheStore,\n\toptions: WithCachingOptions\n): ((input: I) => Promise<O>) => {\n\tconst cached = async (input: I): Promise<O> => {\n\t\tconst cacheKey = options.keyFn(input)\n\n\t\t// Try to get from cache\n\t\tconst cached = await cacheStore.get<O>(cacheKey)\n\t\tif (cached !== undefined) {\n\t\t\treturn cached\n\t\t}\n\n\t\t// Not in cache, call function\n\t\tconst result = await fn(input)\n\n\t\t// Store in cache\n\t\tawait cacheStore.set(cacheKey, result, options.ttlMs)\n\n\t\treturn result\n\t}\n\n\t// Preserve function name for debugging\n\tObject.defineProperty(cached, 'name', {\n\t\tvalue: `withCaching(${fn.name || 'anonymous'})`,\n\t})\n\n\treturn cached\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,eACZ,IACA,YACA,YACgC;CAChC,MAAM,SAAS,OAAO,UAAyB;EAC9C,MAAM,WAAW,QAAQ,MAAM,MAAM;EAGrC,MAAMA,WAAS,MAAM,WAAW,IAAO,SAAS;AAChD,MAAIA,aAAW,OACd,QAAOA;EAIR,MAAM,SAAS,MAAM,GAAG,MAAM;AAG9B,QAAM,WAAW,IAAI,UAAU,QAAQ,QAAQ,MAAM;AAErD,SAAO;;AAIR,QAAO,eAAe,QAAQ,QAAQ,EACrC,OAAO,eAAe,GAAG,QAAQ,YAAY,IAC7C,CAAC;AAEF,QAAO"}
|
|
@@ -36,4 +36,4 @@ interface WithCachingOptions {
|
|
|
36
36
|
declare const withCaching: <I extends Record<string, any>, O>(fn: (input: I) => Promise<O>, cacheStore: CacheStore, options: WithCachingOptions) => ((input: I) => Promise<O>);
|
|
37
37
|
//#endregion
|
|
38
38
|
export { withCaching as n, WithCachingOptions as t };
|
|
39
|
-
//# sourceMappingURL=with-caching-
|
|
39
|
+
//# sourceMappingURL=with-caching-c8PLIWLG.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-rate-limit-
|
|
1
|
+
{"version":3,"file":"with-rate-limit-B1L4rZzs.js","names":["resetAt: Date"],"sources":["../src/decorators/with-rate-limit.ts"],"sourcesContent":["import type { RateLimiterStore } from '@kuckit/domain'\nimport { AppError, ErrorCode } from '@kuckit/domain'\n\n/**\n * Options for rate limiting decorator\n */\nexport interface WithRateLimitOptions {\n\t/** Rate limit key function - maps input to limit key */\n\tkeyFn: (input: any) => string\n\t/** Bucket capacity (max requests) */\n\tcapacity: number\n\t/** Tokens refilled per second */\n\trefillPerSecond: number\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends AppError {\n\tconstructor(public readonly resetAt: Date) {\n\t\tsuper(ErrorCode.RATE_LIMITED, `Rate limit exceeded. Reset at ${resetAt.toISOString()}`, {\n\t\t\tstatusCode: 429,\n\t\t\tmeta: { resetAt },\n\t\t})\n\t}\n}\n\n/**\n * Wraps a use case with rate limiting\n * - Uses token bucket algorithm\n * - Per-input rate limit tracking via keyFn\n * - Throws RateLimitError when limit exceeded\n *\n * @example\n * ```ts\n * const limitedCreatePost = withRateLimit(\n * createPost,\n * rateLimiterStore,\n * {\n * keyFn: (input) => `user:${input.userId}`,\n * capacity: 10,\n * refillPerSecond: 1, // 1 request per second\n * }\n * )\n * ```\n */\nexport const withRateLimit = <I extends Record<string, any>, O>(\n\tfn: (input: I) => Promise<O>,\n\trateLimiterStore: RateLimiterStore,\n\toptions: WithRateLimitOptions\n): ((input: I) => Promise<O>) => {\n\tconst limited = async (input: I): Promise<O> => {\n\t\tconst limitKey = options.keyFn(input)\n\n\t\tconst result = await rateLimiterStore.checkLimit(\n\t\t\tlimitKey,\n\t\t\toptions.capacity,\n\t\t\toptions.refillPerSecond\n\t\t)\n\n\t\tif (!result.allowed) {\n\t\t\tthrow new RateLimitError(result.resetAt)\n\t\t}\n\n\t\t// Rate limit allows, call function\n\t\treturn await fn(input)\n\t}\n\n\t// Preserve function name for debugging\n\tObject.defineProperty(limited, 'name', {\n\t\tvalue: `withRateLimit(${fn.name || 'anonymous'})`,\n\t})\n\n\treturn limited\n}\n"],"mappings":";;;;;;AAkBA,IAAa,iBAAb,cAAoC,SAAS;CAC5C,YAAY,AAAgBA,SAAe;AAC1C,QAAM,UAAU,cAAc,iCAAiC,QAAQ,aAAa,IAAI;GACvF,YAAY;GACZ,MAAM,EAAE,SAAS;GACjB,CAAC;EAJyB;;;;;;;;;;;;;;;;;;;;;;AA2B7B,MAAa,iBACZ,IACA,kBACA,YACgC;CAChC,MAAM,UAAU,OAAO,UAAyB;EAC/C,MAAM,WAAW,QAAQ,MAAM,MAAM;EAErC,MAAM,SAAS,MAAM,iBAAiB,WACrC,UACA,QAAQ,UACR,QAAQ,gBACR;AAED,MAAI,CAAC,OAAO,QACX,OAAM,IAAI,eAAe,OAAO,QAAQ;AAIzC,SAAO,MAAM,GAAG,MAAM;;AAIvB,QAAO,eAAe,SAAS,QAAQ,EACtC,OAAO,iBAAiB,GAAG,QAAQ,YAAY,IAC/C,CAAC;AAEF,QAAO"}
|
|
@@ -42,4 +42,4 @@ declare class RateLimitError extends AppError {
|
|
|
42
42
|
declare const withRateLimit: <I extends Record<string, any>, O>(fn: (input: I) => Promise<O>, rateLimiterStore: RateLimiterStore, options: WithRateLimitOptions) => ((input: I) => Promise<O>);
|
|
43
43
|
//#endregion
|
|
44
44
|
export { WithRateLimitOptions as n, withRateLimit as r, RateLimitError as t };
|
|
45
|
-
//# sourceMappingURL=with-rate-limit-
|
|
45
|
+
//# sourceMappingURL=with-rate-limit-CK5GHSfo.d.ts.map
|