stratal 0.0.25 → 0.0.26
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/bin/quarry.mjs +60 -4
- package/dist/bin/quarry.mjs.map +1 -1
- package/dist/cache/index.d.mts +1 -1
- package/dist/cache/index.mjs +2 -2
- package/dist/{command-4HnKnC-G.d.mts → command-DoBD2Cwl.d.mts} +2 -2
- package/dist/{command-4HnKnC-G.d.mts.map → command-DoBD2Cwl.d.mts.map} +1 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.mjs +2 -2
- package/dist/{controller.decorator-DKeZ71aP.mjs → controller.decorator-YSTPQntu.mjs} +3 -3
- package/dist/{controller.decorator-DKeZ71aP.mjs.map → controller.decorator-YSTPQntu.mjs.map} +1 -1
- package/dist/cron/index.d.mts +1 -1
- package/dist/cron/index.mjs +1 -1
- package/dist/{cron.module-DgxLe8Xy.mjs → cron.module-C81HTzR7.mjs} +3 -3
- package/dist/{cron.module-DgxLe8Xy.mjs.map → cron.module-C81HTzR7.mjs.map} +1 -1
- package/dist/di/index.d.mts +2 -2
- package/dist/di/index.mjs +2 -2
- package/dist/{di-B0NXIdRF.mjs → di-D7qmrAir.mjs} +44 -3
- package/dist/di-D7qmrAir.mjs.map +1 -0
- package/dist/email/index.d.mts +2 -2
- package/dist/email/index.mjs +3 -3
- package/dist/errors/index.d.mts +2 -2
- package/dist/errors/index.mjs +3 -3
- package/dist/{errors-EUtwVfNm.mjs → errors-C01O2T-n.mjs} +19 -4
- package/dist/errors-C01O2T-n.mjs.map +1 -0
- package/dist/events/index.mjs +1 -1
- package/dist/{events-zbCMY_Gf.mjs → events-BhEQuT1X.mjs} +2 -2
- package/dist/{events-zbCMY_Gf.mjs.map → events-BhEQuT1X.mjs.map} +1 -1
- package/dist/{exception-context-Bd5Hk2c_.mjs → exception-context-D-kvney-.mjs} +2 -2
- package/dist/{exception-context-Bd5Hk2c_.mjs.map → exception-context-D-kvney-.mjs.map} +1 -1
- package/dist/{gateway-context-I0tKgGfh.mjs → gateway-context-m7kEzRa2.mjs} +4 -4
- package/dist/{gateway-context-I0tKgGfh.mjs.map → gateway-context-m7kEzRa2.mjs.map} +1 -1
- package/dist/guards/index.d.mts +1 -1
- package/dist/{hono-app-C7-1m9eK.mjs → hono-app-COAgmutc.mjs} +18 -11
- package/dist/hono-app-COAgmutc.mjs.map +1 -0
- package/dist/{http-method.decorator-xCuGoZPC.mjs → http-method.decorator-BljM8BDj.mjs} +2 -2
- package/dist/{http-method.decorator-xCuGoZPC.mjs.map → http-method.decorator-BljM8BDj.mjs.map} +1 -1
- package/dist/i18n/index.d.mts +10 -3
- package/dist/i18n/index.d.mts.map +1 -1
- package/dist/i18n/index.mjs +3 -3
- package/dist/{i18n.module-JOPUNpvi.mjs → i18n.module-B2DvWUPa.mjs} +24 -9
- package/dist/i18n.module-B2DvWUPa.mjs.map +1 -0
- package/dist/{index-BPJSBHhq.d.mts → index-CNuFQSNj.d.mts} +6 -4
- package/dist/{index-BPJSBHhq.d.mts.map → index-CNuFQSNj.d.mts.map} +1 -1
- package/dist/{index-C_t8VVQD.d.mts → index-uybm0bhQ.d.mts} +100 -6
- package/dist/index-uybm0bhQ.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{lazy-module-loader-DZQxOgRZ.d.mts → lazy-module-loader-M6YKudNL.d.mts} +2 -2
- package/dist/{lazy-module-loader-DZQxOgRZ.d.mts.map → lazy-module-loader-M6YKudNL.d.mts.map} +1 -1
- package/dist/{locale-path.service-DzA01Kvc.mjs → locale-path.service-CH0CaxwH.mjs} +3 -3
- package/dist/{locale-path.service-DzA01Kvc.mjs.map → locale-path.service-CH0CaxwH.mjs.map} +1 -1
- package/dist/{locale-url.service-DwTXZid3.mjs → locale-url.service-6bgia24_.mjs} +2 -2
- package/dist/{locale-url.service-DwTXZid3.mjs.map → locale-url.service-6bgia24_.mjs.map} +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/module/index.d.mts +2 -2
- package/dist/module/index.mjs +2 -2
- package/dist/{module-registry-MfWmniZ7.mjs → module-registry-NxX5O0Qk.mjs} +4 -4
- package/dist/{module-registry-MfWmniZ7.mjs.map → module-registry-NxX5O0Qk.mjs.map} +1 -1
- package/dist/openapi/index.d.mts +2 -2
- package/dist/openapi/index.mjs +1 -1
- package/dist/{openapi-BKDwQKh-.mjs → openapi-CMwuCp31.mjs} +3 -3
- package/dist/{openapi-BKDwQKh-.mjs.map → openapi-CMwuCp31.mjs.map} +1 -1
- package/dist/{openapi.service-CM40bnBB.d.mts → openapi.service-2rvJBCEg.d.mts} +2 -2
- package/dist/{openapi.service-CM40bnBB.d.mts.map → openapi.service-2rvJBCEg.d.mts.map} +1 -1
- package/dist/quarry/index.d.mts +3 -3
- package/dist/quarry/index.mjs +1 -1
- package/dist/quarry/runner.d.mts +6 -6
- package/dist/quarry/runner.mjs +5 -5
- package/dist/{quarry-registry-CsStq0DB.d.mts → quarry-registry-DRnV-DDa.d.mts} +3 -3
- package/dist/{quarry-registry-CsStq0DB.d.mts.map → quarry-registry-DRnV-DDa.d.mts.map} +1 -1
- package/dist/{quarry.module-BOgcNJMU.mjs → quarry.module-CcGxU2dJ.mjs} +3 -3
- package/dist/{quarry.module-BOgcNJMU.mjs.map → quarry.module-CcGxU2dJ.mjs.map} +1 -1
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +2 -2
- package/dist/{queue.module-DSAH88gZ.mjs → queue.module-CEs4_kEM.mjs} +15 -8
- package/dist/{queue.module-DSAH88gZ.mjs.map → queue.module-CEs4_kEM.mjs.map} +1 -1
- package/dist/{r2-storage.provider-BJ4j23W6.mjs → r2-storage.provider-BoZmR6Ut.mjs} +2 -2
- package/dist/{r2-storage.provider-BJ4j23W6.mjs.map → r2-storage.provider-BoZmR6Ut.mjs.map} +1 -1
- package/dist/{rate-limit.decorator-B35jBEVD.mjs → rate-limit.decorator-Djs4oYDB.mjs} +2 -2
- package/dist/{rate-limit.decorator-B35jBEVD.mjs.map → rate-limit.decorator-Djs4oYDB.mjs.map} +1 -1
- package/dist/rate-limiter/index.d.mts +54 -47
- package/dist/rate-limiter/index.d.mts.map +1 -1
- package/dist/rate-limiter/index.mjs +16 -7
- package/dist/rate-limiter/index.mjs.map +1 -1
- package/dist/{route-registration.service-HN8WgIis.mjs → route-registration.service-CDPQKpm4.mjs} +9 -9
- package/dist/{route-registration.service-HN8WgIis.mjs.map → route-registration.service-CDPQKpm4.mjs.map} +1 -1
- package/dist/{route-registry-CtW26Suv.mjs → route-registry-BvLJisvK.mjs} +3 -3
- package/dist/{route-registry-CtW26Suv.mjs.map → route-registry-BvLJisvK.mjs.map} +1 -1
- package/dist/router/index.d.mts +2 -2
- package/dist/router/index.mjs +16 -16
- package/dist/{router-OCnf4VB6.mjs → router-DwyqEXgf.mjs} +13 -13
- package/dist/{router-OCnf4VB6.mjs.map → router-DwyqEXgf.mjs.map} +1 -1
- package/dist/{router-resolver-CMNuw-s0.mjs → router-resolver-sUV_jTrU.mjs} +2 -2
- package/dist/{router-resolver-CMNuw-s0.mjs.map → router-resolver-sUV_jTrU.mjs.map} +1 -1
- package/dist/seeder/index.d.mts +2 -2
- package/dist/seeder/index.mjs +3 -3
- package/dist/{seeder-DI-rUoZx.mjs → seeder-BPGY5rUb.mjs} +4 -4
- package/dist/{seeder-DI-rUoZx.mjs.map → seeder-BPGY5rUb.mjs.map} +1 -1
- package/dist/{seeder-registry-B5FwBeCU.mjs → seeder-registry-DEvCycsT.mjs} +3 -3
- package/dist/{seeder-registry-B5FwBeCU.mjs.map → seeder-registry-DEvCycsT.mjs.map} +1 -1
- package/dist/{seeder.module-DaY0RYoB.mjs → seeder.module-CIwQbdN4.mjs} +2 -2
- package/dist/{seeder.module-DaY0RYoB.mjs.map → seeder.module-CIwQbdN4.mjs.map} +1 -1
- package/dist/storage/index.d.mts +1 -1
- package/dist/storage/index.mjs +2 -2
- package/dist/storage/providers/index.mjs +1 -1
- package/dist/{storage-BE6-kzaN.mjs → storage-C30X81CS.mjs} +7 -7
- package/dist/{storage-BE6-kzaN.mjs.map → storage-C30X81CS.mjs.map} +1 -1
- package/dist/{storage.error-Dai3rShJ.mjs → storage.error-BStXPmO4.mjs} +2 -2
- package/dist/{storage.error-Dai3rShJ.mjs.map → storage.error-BStXPmO4.mjs.map} +1 -1
- package/dist/{stratal-DtAj21uF.mjs → stratal-BL6FKUM_.mjs} +84 -35
- package/dist/stratal-BL6FKUM_.mjs.map +1 -0
- package/dist/{stratal-Bmc6WT3k.d.mts → stratal-D5j_I14G.d.mts} +13 -3
- package/dist/stratal-D5j_I14G.d.mts.map +1 -0
- package/dist/trailing-slash-2SctvePW.mjs +80 -0
- package/dist/trailing-slash-2SctvePW.mjs.map +1 -0
- package/dist/{uri-h6ITRpqr.mjs → uri-iwofWJ_T.mjs} +12 -10
- package/dist/uri-iwofWJ_T.mjs.map +1 -0
- package/dist/{versioning.service-B4rtmgMQ.mjs → versioning.service-CCa2oYMJ.mjs} +3 -3
- package/dist/{versioning.service-B4rtmgMQ.mjs.map → versioning.service-CCa2oYMJ.mjs.map} +1 -1
- package/dist/websocket/index.d.mts +1 -1
- package/dist/websocket/index.mjs +1 -1
- package/dist/workers/index.d.mts +1 -1
- package/dist/workers/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/di-B0NXIdRF.mjs.map +0 -1
- package/dist/errors-EUtwVfNm.mjs.map +0 -1
- package/dist/hono-app-C7-1m9eK.mjs.map +0 -1
- package/dist/i18n.module-JOPUNpvi.mjs.map +0 -1
- package/dist/index-C_t8VVQD.d.mts.map +0 -1
- package/dist/stratal-Bmc6WT3k.d.mts.map +0 -1
- package/dist/stratal-DtAj21uF.mjs.map +0 -1
- package/dist/trailing-slash-CFyw8nYu.mjs +0 -34
- package/dist/trailing-slash-CFyw8nYu.mjs.map +0 -1
- package/dist/uri-h6ITRpqr.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as Container, Cn as Middleware, Fn as DynamicModule, Hn as OnInitialize, Ir as ApplicationError, Nn as AsyncModuleOptions, Vn as OnException, f as ExceptionHandler, l as HttpException, st as RouterContext, wn as Next, zn as ModuleContext } from "../index-uybm0bhQ.mjs";
|
|
2
2
|
import { t as Macroable } from "../index-0ItCjaqw.mjs";
|
|
3
3
|
import { t as StratalEnv } from "../env-ug22bJj7.mjs";
|
|
4
4
|
import { t as Constructor } from "../types-CmV_9xBD.mjs";
|
|
@@ -91,50 +91,6 @@ declare class Limit {
|
|
|
91
91
|
get customResponse(): RateLimitResponseHandler | undefined;
|
|
92
92
|
}
|
|
93
93
|
//#endregion
|
|
94
|
-
//#region src/rate-limiter/stores/rate-limiter-store.interface.d.ts
|
|
95
|
-
/**
|
|
96
|
-
* Result of a single hit against the rate limiter (registry-internal).
|
|
97
|
-
*
|
|
98
|
-
* The store no longer participates in the increment — it's a typed KV.
|
|
99
|
-
* `RateLimiterRegistry.handle()` produces this value as it runs the
|
|
100
|
-
* get-modify-set sequence.
|
|
101
|
-
*/
|
|
102
|
-
interface RateLimitHit {
|
|
103
|
-
/** Counter value AFTER the increment (1 on first hit). */
|
|
104
|
-
count: number;
|
|
105
|
-
/** Absolute reset timestamp in milliseconds since epoch. */
|
|
106
|
-
resetAt: number;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Pluggable backend for rate-limit storage — a typed key-value store with TTL.
|
|
110
|
-
*
|
|
111
|
-
* The framework ships `KvRateLimiterStore` (Cloudflare KV) and
|
|
112
|
-
* `InMemoryRateLimiterStore` (tests). Users can register a custom
|
|
113
|
-
* implementation through `RateLimiterModule.forRoot({ store: { useClass: ... } })`.
|
|
114
|
-
*
|
|
115
|
-
* The increment logic lives in `RateLimiterRegistry`; the store only persists
|
|
116
|
-
* arbitrary values keyed by string. Same shape consumed by the better-auth
|
|
117
|
-
* bridge in `@stratal/framework/auth`, which stores its own `RateLimit`
|
|
118
|
-
* records here under a separate key namespace.
|
|
119
|
-
*/
|
|
120
|
-
interface IRateLimiterStore {
|
|
121
|
-
/**
|
|
122
|
-
* Read the value at `key`. Returns `null` when missing or expired.
|
|
123
|
-
* Implementations are responsible for honouring TTL (lazy or active).
|
|
124
|
-
*/
|
|
125
|
-
get<T = unknown>(key: string): Promise<T | null>;
|
|
126
|
-
/**
|
|
127
|
-
* Write `value` at `key` with `ttlSeconds` TTL. Overwrites any existing
|
|
128
|
-
* value. The TTL resets on every write — callers compute the remaining
|
|
129
|
-
* window themselves and pass it explicitly.
|
|
130
|
-
*/
|
|
131
|
-
set<T = unknown>(key: string, value: T, ttlSeconds: number): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
* Remove `key`. No-op when missing.
|
|
134
|
-
*/
|
|
135
|
-
delete(key: string): Promise<void>;
|
|
136
|
-
}
|
|
137
|
-
//#endregion
|
|
138
94
|
//#region src/rate-limiter/rate-limiter-registry.d.ts
|
|
139
95
|
/**
|
|
140
96
|
* Resolver function registered via {@link RateLimiterRegistry.for}. Receives
|
|
@@ -162,9 +118,16 @@ type LimitResolver = (ctx: RouterContext) => Limit | Limit[] | Promise<Limit | L
|
|
|
162
118
|
* `customRules` interop.
|
|
163
119
|
*/
|
|
164
120
|
declare class RateLimiterRegistry extends Macroable {
|
|
165
|
-
private readonly
|
|
121
|
+
private readonly container;
|
|
166
122
|
private readonly resolvers;
|
|
167
|
-
constructor(
|
|
123
|
+
constructor(container: Container);
|
|
124
|
+
/**
|
|
125
|
+
* Resolve the store per access instead of capturing it at construction.
|
|
126
|
+
* The registry is a singleton built during module init; lazy resolution
|
|
127
|
+
* keeps later `RATE_LIMITER_TOKENS.Store` overrides (e.g. the testing
|
|
128
|
+
* harness disabling limits) effective.
|
|
129
|
+
*/
|
|
130
|
+
private get store();
|
|
168
131
|
/**
|
|
169
132
|
* Register a named limiter. Names must be unique; calling `for()` again
|
|
170
133
|
* with the same name overwrites the previous resolver (matches Laravel
|
|
@@ -190,6 +153,50 @@ declare class RateLimiterRegistry extends Macroable {
|
|
|
190
153
|
private makeHeaders;
|
|
191
154
|
}
|
|
192
155
|
//#endregion
|
|
156
|
+
//#region src/rate-limiter/stores/rate-limiter-store.interface.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Result of a single hit against the rate limiter (registry-internal).
|
|
159
|
+
*
|
|
160
|
+
* The store no longer participates in the increment — it's a typed KV.
|
|
161
|
+
* `RateLimiterRegistry.handle()` produces this value as it runs the
|
|
162
|
+
* get-modify-set sequence.
|
|
163
|
+
*/
|
|
164
|
+
interface RateLimitHit {
|
|
165
|
+
/** Counter value AFTER the increment (1 on first hit). */
|
|
166
|
+
count: number;
|
|
167
|
+
/** Absolute reset timestamp in milliseconds since epoch. */
|
|
168
|
+
resetAt: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Pluggable backend for rate-limit storage — a typed key-value store with TTL.
|
|
172
|
+
*
|
|
173
|
+
* The framework ships `KvRateLimiterStore` (Cloudflare KV) and
|
|
174
|
+
* `InMemoryRateLimiterStore` (tests). Users can register a custom
|
|
175
|
+
* implementation through `RateLimiterModule.forRoot({ store: { useClass: ... } })`.
|
|
176
|
+
*
|
|
177
|
+
* The increment logic lives in `RateLimiterRegistry`; the store only persists
|
|
178
|
+
* arbitrary values keyed by string. Same shape consumed by the better-auth
|
|
179
|
+
* bridge in `@stratal/framework/auth`, which stores its own `RateLimit`
|
|
180
|
+
* records here under a separate key namespace.
|
|
181
|
+
*/
|
|
182
|
+
interface IRateLimiterStore {
|
|
183
|
+
/**
|
|
184
|
+
* Read the value at `key`. Returns `null` when missing or expired.
|
|
185
|
+
* Implementations are responsible for honouring TTL (lazy or active).
|
|
186
|
+
*/
|
|
187
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
188
|
+
/**
|
|
189
|
+
* Write `value` at `key` with `ttlSeconds` TTL. Overwrites any existing
|
|
190
|
+
* value. The TTL resets on every write — callers compute the remaining
|
|
191
|
+
* window themselves and pass it explicitly.
|
|
192
|
+
*/
|
|
193
|
+
set<T = unknown>(key: string, value: T, ttlSeconds: number): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Remove `key`. No-op when missing.
|
|
196
|
+
*/
|
|
197
|
+
delete(key: string): Promise<void>;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
193
200
|
//#region src/rate-limiter/stores/store-factory.d.ts
|
|
194
201
|
/**
|
|
195
202
|
* Configuration for `RateLimiterModule.forRoot()`. Picks the backing store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/rate-limiter/errors.ts","../../src/rate-limiter/limit.ts","../../src/rate-limiter/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/rate-limiter/errors.ts","../../src/rate-limiter/limit.ts","../../src/rate-limiter/rate-limiter-registry.ts","../../src/rate-limiter/stores/rate-limiter-store.interface.ts","../../src/rate-limiter/stores/store-factory.ts","../../src/rate-limiter/rate-limiter.module.ts","../../src/rate-limiter/rate-limiter.tokens.ts","../../src/rate-limiter/throttle.middleware.ts","../../src/rate-limiter/decorators/rate-limit.decorator.ts","../../src/rate-limiter/stores/kv-store.ts","../../src/rate-limiter/stores/memory-store.ts"],"mappings":";;;;;;;;;;;;;AAYA;;;;cAAa,oBAAA,SAA6B,aAAa;EAAA,SAEnC,IAAA;IAAQ,UAAA;IAAoB,KAAA;IAAe,OAAA;EAAA;cAA3C,IAAA;IAAQ,UAAA;IAAoB,KAAA;IAAe,OAAA;EAAA;AAAA;AAAA,cAMlD,gBAAA,SAAyB,gBAAgB;;;;;;;UCdrC,gBAAA;EACf,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,mBAAA;AAAA;;;;;;;KASU,wBAAA,IACV,GAAA,EAAK,aAAA,EACL,OAAA,EAAS,gBAAA,KACN,QAAA,GAAW,OAAA,CAAQ,QAAA;;;;;ADRwD;AAMhF;;;;AAAsD;;;;ACdtD;;;;cAmCa,KAAA;EAAA,SAKO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;;;;ACdtD;;;ADcsD,iBQ8BtC,aAAA,CAAc,MAAA,UAAgB,WAAoB;;;;;;;;ARtClE;;;;;;;cSGa,kBAAA,YAA8B,iBAAA;EAAA,iBACZ,KAAA;cAAA,KAAA,EAAO,YAAA;EAE9B,GAAA,IAAO,GAAA,WAAc,OAAA,CAAQ,CAAA;EAI7B,GAAA,IAAO,GAAA,UAAa,KAAA,EAAO,CAAA,EAAG,UAAA,WAAqB,OAAA;EAKnD,MAAA,CAAO,GAAA,WAAc,OAAA;AAAA;;;;;;;;;ATf7B;;;cUIa,wBAAA,YAAoC,iBAAA;EAAA,iBAC9B,OAAA;EAEjB,GAAA,IAAO,GAAA,WAAc,OAAA,CAAQ,CAAA;EAU7B,GAAA,IAAO,GAAA,UAAa,KAAA,EAAO,CAAA,EAAG,UAAA,WAAqB,OAAA;EAKnD,MAAA,CAAO,GAAA,WAAc,OAAA;AAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as Singleton, n as CONTAINER_TOKEN, p as inject, r as DI_TOKENS } from "../di-D7qmrAir.mjs";
|
|
2
2
|
import { n as __decorateParam, t as __decorate } from "../decorate-CuAoSZvs.mjs";
|
|
3
3
|
import { t as Macroable } from "../macroable-cvDTFZ_A.mjs";
|
|
4
4
|
import { n as Module } from "../module.decorator-CYHY6pG5.mjs";
|
|
5
|
-
import { c as RATE_LIMITER_TOKENS, l as RateLimiterError, s as createThrottleMiddleware, u as TooManyRequestsError } from "../module-registry-
|
|
5
|
+
import { c as RATE_LIMITER_TOKENS, l as RateLimiterError, s as createThrottleMiddleware, u as TooManyRequestsError } from "../module-registry-NxX5O0Qk.mjs";
|
|
6
6
|
import "../module/index.mjs";
|
|
7
7
|
import { CACHE_TOKENS, CacheModule } from "../cache/index.mjs";
|
|
8
|
-
import { n as getRateLimits, t as RateLimit } from "../rate-limit.decorator-
|
|
8
|
+
import { n as getRateLimits, t as RateLimit } from "../rate-limit.decorator-Djs4oYDB.mjs";
|
|
9
9
|
//#region src/rate-limiter/limit.ts
|
|
10
10
|
/**
|
|
11
11
|
* A single rate limit window.
|
|
@@ -81,11 +81,20 @@ var Limit = class Limit {
|
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/rate-limiter/rate-limiter-registry.ts
|
|
83
83
|
let RateLimiterRegistry = class RateLimiterRegistry extends Macroable {
|
|
84
|
-
|
|
84
|
+
container;
|
|
85
85
|
resolvers = /* @__PURE__ */ new Map();
|
|
86
|
-
constructor(
|
|
86
|
+
constructor(container) {
|
|
87
87
|
super();
|
|
88
|
-
this.
|
|
88
|
+
this.container = container;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the store per access instead of capturing it at construction.
|
|
92
|
+
* The registry is a singleton built during module init; lazy resolution
|
|
93
|
+
* keeps later `RATE_LIMITER_TOKENS.Store` overrides (e.g. the testing
|
|
94
|
+
* harness disabling limits) effective.
|
|
95
|
+
*/
|
|
96
|
+
get store() {
|
|
97
|
+
return this.container.resolve(RATE_LIMITER_TOKENS.Store);
|
|
89
98
|
}
|
|
90
99
|
/**
|
|
91
100
|
* Register a named limiter. Names must be unique; calling `for()` again
|
|
@@ -182,7 +191,7 @@ let RateLimiterRegistry = class RateLimiterRegistry extends Macroable {
|
|
|
182
191
|
};
|
|
183
192
|
}
|
|
184
193
|
};
|
|
185
|
-
RateLimiterRegistry = __decorate([Singleton(), __decorateParam(0, inject(
|
|
194
|
+
RateLimiterRegistry = __decorate([Singleton(), __decorateParam(0, inject(DI_TOKENS.Container))], RateLimiterRegistry);
|
|
186
195
|
//#endregion
|
|
187
196
|
//#region src/rate-limiter/stores/kv-store.ts
|
|
188
197
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/rate-limiter/limit.ts","../../src/rate-limiter/rate-limiter-registry.ts","../../src/rate-limiter/stores/kv-store.ts","../../src/rate-limiter/stores/memory-store.ts","../../src/rate-limiter/stores/store-factory.ts","../../src/rate-limiter/rate-limiter.module.ts"],"sourcesContent":["import type { RouterContext } from '../router/router-context'\n\n/**\n * Standard rate-limit response headers passed to custom response handlers.\n * Keys are canonical HTTP header names; values are the stringified counts.\n */\nexport interface RateLimitHeaders {\n 'Retry-After': string\n 'X-RateLimit-Limit': string\n 'X-RateLimit-Remaining': string\n 'X-RateLimit-Reset': string\n}\n\n/**\n * Custom response handler invoked when a limit is exceeded and the user\n * supplied `.response()` on the {@link Limit}. Receives the request context\n * and the precomputed standard headers (which the handler can spread, drop,\n * or override).\n */\nexport type RateLimitResponseHandler = (\n ctx: RouterContext,\n headers: RateLimitHeaders,\n) => Response | Promise<Response>\n\n/**\n * A single rate limit window.\n *\n * Build via the static factories (`perSecond`, `perMinute`, `perMinutes`,\n * `perHour`, `perDay`, `none`). Chain `.by(key)` to scope per-actor and\n * `.response(handler)` to override the default 429 response.\n *\n * Returned (singly or as an array) by limiter resolvers registered via\n * `RateLimiterRegistry.for()`.\n *\n * @example\n * ```typescript\n * Limit.perMinute(60).by(ctx.header('cf-connecting-ip') ?? 'global')\n * Limit.perHour(100).by(userId)\n * Limit.none() // bypass\n * ```\n */\nexport class Limit {\n private _key?: string\n private _customResponse?: RateLimitResponseHandler\n\n private constructor(\n public readonly windowSeconds: number,\n public readonly max: number,\n public readonly disabled = false,\n ) {}\n\n static perSecond(max: number): Limit {\n return new Limit(1, max)\n }\n\n static perSeconds(seconds: number, max: number): Limit {\n return new Limit(seconds, max)\n }\n\n static perMinute(max: number): Limit {\n return new Limit(60, max)\n }\n\n static perMinutes(minutes: number, max: number): Limit {\n return new Limit(minutes * 60, max)\n }\n\n static perHour(max: number): Limit {\n return new Limit(60 * 60, max)\n }\n\n static perDay(max: number): Limit {\n return new Limit(24 * 60 * 60, max)\n }\n\n /** Bypass the limiter entirely for this request. */\n static none(): Limit {\n return new Limit(0, 0, true)\n }\n\n /** Scope this limit to a specific actor (user id, IP, tenant, etc.). */\n by(key: string | number): this {\n this._key = String(key)\n return this\n }\n\n /**\n * Override the default 429 response. The handler receives the standard\n * `RateLimitHeaders` so it can spread them onto its own Response or omit\n * them as it sees fit.\n */\n response(handler: RateLimitResponseHandler): this {\n this._customResponse = handler\n return this\n }\n\n get key(): string | undefined {\n return this._key\n }\n\n get customResponse(): RateLimitResponseHandler | undefined {\n return this._customResponse\n }\n}\n","import { inject } from '../di'\nimport { Singleton } from '../di/decorators'\nimport { Macroable } from '../macroable'\nimport type { Next } from '../router/middleware.interface'\nimport type { RouterContext } from '../router/router-context'\nimport { RateLimiterError, TooManyRequestsError } from './errors'\nimport type { Limit, RateLimitHeaders } from './limit'\nimport { RATE_LIMITER_TOKENS } from './rate-limiter.tokens'\nimport type { IRateLimiterStore, RateLimitHit } from './stores/rate-limiter-store.interface'\n\n/**\n * Resolver function registered via {@link RateLimiterRegistry.for}. Receives\n * the request context and returns the limit (or limits) that apply to this\n * request. Return `Limit.none()` to bypass for the current request.\n */\nexport type LimitResolver = (\n ctx: RouterContext,\n) => Limit | Limit[] | Promise<Limit | Limit[]>\n\ninterface StoredHit {\n count: number\n resetAt: number\n}\n\n/**\n * Central registry of named rate limiters and the request-time enforcement\n * pipeline. Resolved as a singleton; consumed by `ThrottleMiddleware`.\n *\n * Register limiters in a module's `onInitialize` hook:\n * ```typescript\n * @Module({})\n * export class RateLimitsModule implements OnInitialize {\n * onInitialize({ container }: ModuleContext): void {\n * const limiter = container.resolve<RateLimiterRegistry>(RATE_LIMITER_TOKENS.Registry)\n * limiter.for('api', (ctx) => Limit.perMinute(60).by(ctx.header('cf-connecting-ip') ?? '*'))\n * }\n * }\n * ```\n *\n * Extensible via `Macroable`: adapter packages (e.g. `@stratal/framework/auth`)\n * can attach extra registration methods such as `forPath()` for better-auth\n * `customRules` interop.\n */\n// IMPORTANT: do not pass a token to @Singleton — that would self-register\n// the class globally at module-load time, making the Registry resolvable\n// even when the user never imported RateLimiterModule. We rely on\n// RateLimiterModule providers being the only binding source, so\n// `{ isOptional: true }` in ThrottleMiddleware correctly returns undefined\n// when the module is missing.\n@Singleton()\nexport class RateLimiterRegistry extends Macroable {\n private readonly resolvers = new Map<string, LimitResolver>()\n\n constructor(\n @inject(RATE_LIMITER_TOKENS.Store) private readonly store: IRateLimiterStore,\n ) {\n super()\n }\n\n /**\n * Register a named limiter. Names must be unique; calling `for()` again\n * with the same name overwrites the previous resolver (matches Laravel\n * `RateLimiter::for` semantics — last definition wins).\n */\n for(name: string, resolver: LimitResolver): void {\n this.resolvers.set(name, resolver)\n }\n\n has(name: string): boolean {\n return this.resolvers.has(name)\n }\n\n /**\n * Enforce the named limiter for the current request. Called by\n * `ThrottleMiddleware` (the per-name class produced by\n * `createThrottleMiddleware`). Resolves the limiter, increments the store\n * for each non-bypassed limit, sets `X-RateLimit-*` headers on success, and\n * either invokes the limit's custom `.response()` or throws\n * {@link TooManyRequestsError} when a limit is exceeded.\n */\n async handle(name: string, ctx: RouterContext, next: Next): Promise<Response | void> {\n const resolver = this.resolvers.get(name)\n if (!resolver) {\n throw new RateLimiterError(`Rate limiter \"${name}\" is not defined. Register it with limiter.for(\"${name}\", ...) in a module's onInitialize hook.`)\n }\n\n const resolved = await resolver(ctx)\n const limits = Array.isArray(resolved) ? resolved : [resolved]\n const active = limits.filter((l) => !l.disabled)\n\n if (active.length === 0) {\n return next()\n }\n\n let mostRestrictive: { limit: Limit; remaining: number; resetAt: number } | undefined\n let exceeded: { limit: Limit; resetAt: number } | undefined\n\n for (const limit of active) {\n const key = this.makeKey(name, limit.windowSeconds, limit.key)\n const hit = await this.hit(key, limit.windowSeconds)\n\n if (hit.count > limit.max) {\n if (!exceeded || hit.resetAt > exceeded.resetAt) {\n exceeded = { limit, resetAt: hit.resetAt }\n }\n continue\n }\n\n const remaining = limit.max - hit.count\n if (!mostRestrictive || remaining < mostRestrictive.remaining) {\n mostRestrictive = { limit, remaining, resetAt: hit.resetAt }\n }\n }\n\n if (exceeded) {\n const headers = this.makeHeaders(exceeded.limit.max, 0, exceeded.resetAt)\n if (exceeded.limit.customResponse) {\n return exceeded.limit.customResponse(ctx, headers)\n }\n throw new TooManyRequestsError({\n retryAfter: Number(headers['Retry-After']),\n limit: exceeded.limit.max,\n resetAt: exceeded.resetAt,\n })\n }\n\n await next()\n\n if (mostRestrictive) {\n const headers = this.makeHeaders(\n mostRestrictive.limit.max,\n mostRestrictive.remaining,\n mostRestrictive.resetAt,\n )\n // Hono populates ctx.c.res after next() — same pattern as logger.middleware.ts.\n const downstream = ctx.c.res\n downstream.headers.set('X-RateLimit-Limit', headers['X-RateLimit-Limit'])\n downstream.headers.set('X-RateLimit-Remaining', headers['X-RateLimit-Remaining'])\n downstream.headers.set('X-RateLimit-Reset', headers['X-RateLimit-Reset'])\n }\n }\n\n /**\n * Get-modify-set increment over the typed KV store. Not atomic across\n * concurrent edge requests on KV — see `KvRateLimiterStore`'s caveat.\n */\n private async hit(key: string, windowSeconds: number): Promise<RateLimitHit> {\n const now = Date.now()\n const existing = await this.store.get<StoredHit>(key)\n\n let next: StoredHit\n if (!existing || existing.resetAt <= now) {\n next = { count: 1, resetAt: now + windowSeconds * 1000 }\n } else {\n next = { count: existing.count + 1, resetAt: existing.resetAt }\n }\n\n const ttlSeconds = Math.max(1, Math.ceil((next.resetAt - now) / 1000))\n await this.store.set(key, next, ttlSeconds)\n return next\n }\n\n private makeKey(name: string, windowSeconds: number, by: string | undefined): string {\n const actor = by ?? '*'\n return `rl:${name}:${windowSeconds}:${actor}`\n }\n\n private makeHeaders(limit: number, remaining: number, resetAt: number): RateLimitHeaders {\n const retryAfter = Math.max(1, Math.ceil((resetAt - Date.now()) / 1000))\n return {\n 'Retry-After': String(retryAfter),\n 'X-RateLimit-Limit': String(limit),\n 'X-RateLimit-Remaining': String(Math.max(0, remaining)),\n 'X-RateLimit-Reset': String(Math.ceil(resetAt / 1000)),\n }\n }\n}\n","import type { CacheService } from '../../cache/services/cache.service'\nimport type { IRateLimiterStore } from './rate-limiter-store.interface'\n\n/**\n * Cloudflare KV-backed typed KV store.\n *\n * KV's minimum `expirationTtl` is 60 seconds; sub-60s windows are still\n * enforced by the registry's algorithm via the persisted `resetAt`, but\n * the key itself may live in KV longer than the logical window.\n *\n * KV has no native atomic increment, so concurrent writes from different\n * edge locations may undercount under high contention. That's an inherent\n * KV tradeoff — pick `{ useClass: MyDurableObjectStore }` for strict\n * accuracy across edges.\n */\nexport class KvRateLimiterStore implements IRateLimiterStore {\n constructor(private readonly cache: CacheService) {}\n\n async get<T>(key: string): Promise<T | null> {\n return (await this.cache.get<T>(key, 'json')) ?? null\n }\n\n async set<T>(key: string, value: T, ttlSeconds: number): Promise<void> {\n const ttl = Math.max(60, Math.ceil(ttlSeconds))\n await this.cache.put(key, JSON.stringify(value), { expirationTtl: ttl })\n }\n\n async delete(key: string): Promise<void> {\n await this.cache.delete(key)\n }\n}\n","import type { IRateLimiterStore } from './rate-limiter-store.interface'\n\ninterface Entry {\n value: unknown\n expiresAt: number\n}\n\n/**\n * In-process Map-backed typed KV store.\n *\n * Suitable for tests and single-isolate scenarios. Not safe across\n * Cloudflare Worker isolates — entries reset whenever a fresh isolate\n * spins up. Use `KvRateLimiterStore` (or a custom Durable Object store)\n * for production. Expiry is lazy: stale entries are dropped on the next\n * `get`.\n */\nexport class InMemoryRateLimiterStore implements IRateLimiterStore {\n private readonly entries = new Map<string, Entry>()\n\n get<T>(key: string): Promise<T | null> {\n const entry = this.entries.get(key)\n if (!entry) return Promise.resolve(null)\n if (entry.expiresAt <= Date.now()) {\n this.entries.delete(key)\n return Promise.resolve(null)\n }\n return Promise.resolve(entry.value as T)\n }\n\n set<T>(key: string, value: T, ttlSeconds: number): Promise<void> {\n this.entries.set(key, { value, expiresAt: Date.now() + ttlSeconds * 1000 })\n return Promise.resolve()\n }\n\n delete(key: string): Promise<void> {\n this.entries.delete(key)\n return Promise.resolve()\n }\n}\n","import { inject } from '../../di'\nimport { CACHE_TOKENS } from '../../cache/cache.tokens'\nimport type { CacheService } from '../../cache/services/cache.service'\nimport { CONTAINER_TOKEN, type Container } from '../../di'\nimport { Singleton } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport type { StratalEnv } from '../../env'\nimport type { Constructor } from '../../types'\nimport { RateLimiterError } from '../errors'\nimport { RATE_LIMITER_TOKENS } from '../rate-limiter.tokens'\nimport { KvRateLimiterStore } from './kv-store'\nimport { InMemoryRateLimiterStore } from './memory-store'\nimport type { IRateLimiterStore } from './rate-limiter-store.interface'\n\n/**\n * Configuration for `RateLimiterModule.forRoot()`. Picks the backing store.\n *\n * - `'kv'`: Cloudflare KV. `binding` names the KVNamespace on `StratalEnv`.\n * - `'memory'`: in-process Map. Tests / single-isolate only.\n * - `{ useClass }`: any class implementing `IRateLimiterStore`. Resolved\n * from the DI container (so the class can declare its own `@inject` deps,\n * e.g. a Durable Object namespace from `StratalEnv`).\n */\nexport type RateLimiterModuleOptions =\n | { store: 'kv'; binding: keyof StratalEnv }\n | { store: 'memory' }\n | { store: { useClass: Constructor<IRateLimiterStore> } }\n\n// IMPORTANT: see RateLimiterRegistry — no token on @Singleton so the\n// factory isn't globally bound at class-load time. Module providers are\n// the sole binding source, which keeps the \"module not imported\" detection\n// in ThrottleMiddleware working.\n@Singleton()\nexport class RateLimiterStoreFactory {\n constructor(\n @inject(DI_TOKENS.CloudflareEnv) private readonly env: StratalEnv,\n @inject(CACHE_TOKENS.CacheService) private readonly cache: CacheService,\n @inject(CONTAINER_TOKEN) private readonly container: Container,\n @inject(RATE_LIMITER_TOKENS.Options, { isOptional: true })\n private readonly options?: RateLimiterModuleOptions,\n ) {}\n\n create(): IRateLimiterStore {\n if (!this.options) {\n throw new RateLimiterError('RateLimiterModule is not configured. Call RateLimiterModule.forRoot({ store: ... }) to configure a backing store.')\n }\n\n const { store } = this.options\n\n if (store === 'memory') {\n return new InMemoryRateLimiterStore()\n }\n\n if (store === 'kv') {\n const binding = this.env[this.options.binding] as KVNamespace | undefined\n if (!binding) {\n throw new RateLimiterError(`KV binding \"${String(this.options.binding)}\" is not available in the environment.`)\n }\n return new KvRateLimiterStore(this.cache.withBinding(binding))\n }\n\n return this.container.resolve<IRateLimiterStore>(store.useClass)\n }\n}\n","import { CacheModule } from '../cache'\nimport type { ExceptionHandler } from '../errors/exception-handler'\nimport { Module } from '../module'\nimport type { AsyncModuleOptions, DynamicModule, ModuleContext, OnException, OnInitialize } from '../module/types'\nimport { TooManyRequestsError } from './errors'\nimport { RateLimiterRegistry } from './rate-limiter-registry'\nimport { RATE_LIMITER_TOKENS } from './rate-limiter.tokens'\nimport { RateLimiterStoreFactory, type RateLimiterModuleOptions } from './stores/store-factory'\nimport type { IRateLimiterStore } from './stores/rate-limiter-store.interface'\n\n/**\n * Rate limiter module — opt-in, NOT registered automatically by Application.\n *\n * Usage:\n * ```typescript\n * @Module({\n * imports: [RateLimiterModule.forRoot({ store: 'kv', binding: 'RATE_LIMITS' })],\n * })\n * export class AppModule {}\n * ```\n *\n * Define limiters in any module's `onInitialize` hook by resolving\n * `RATE_LIMITER_TOKENS.Registry` from the container. Apply them with\n * `router.throttle('name')` or `@RateLimit('name')`.\n *\n * The module:\n * - eagerly validates the store at app boot (`onInitialize` resolves the\n * factory and calls `create()`); a missing `forRoot` surfaces\n * `RateLimiterError` before any request is served.\n * - registers a `respond()` callback on the `ExceptionHandler` (via\n * `onException`) that injects `Retry-After` and `X-RateLimit-*` headers\n * on every {@link TooManyRequestsError} response, regardless of whether\n * the body was rendered as JSON, HTML, or via Inertia.\n */\n@Module({\n imports: [CacheModule],\n providers: [\n { provide: RATE_LIMITER_TOKENS.Registry, useClass: RateLimiterRegistry },\n { provide: RATE_LIMITER_TOKENS.StoreFactory, useClass: RateLimiterStoreFactory },\n {\n provide: RATE_LIMITER_TOKENS.Store,\n useFactory: (factory: RateLimiterStoreFactory) => factory.create(),\n inject: [RATE_LIMITER_TOKENS.StoreFactory],\n },\n ],\n})\nexport class RateLimiterModule implements OnInitialize, OnException {\n /**\n * Configure the rate limiter with a store choice.\n *\n * @param options - `{ store: 'kv', binding }` | `{ store: 'memory' }` | `{ store: { useClass } }`\n */\n static forRoot(options: RateLimiterModuleOptions): DynamicModule {\n return {\n module: RateLimiterModule,\n providers: [\n { provide: RATE_LIMITER_TOKENS.Options, useValue: options },\n ],\n }\n }\n\n /**\n * Async configuration. Use when store options depend on other services\n * (e.g. ConfigService).\n */\n static forRootAsync(options: AsyncModuleOptions<RateLimiterModuleOptions>): DynamicModule {\n return {\n module: RateLimiterModule,\n providers: [\n {\n provide: RATE_LIMITER_TOKENS.Options,\n useFactory: options.useFactory,\n inject: options.inject,\n },\n ],\n }\n }\n\n /**\n * Eagerly resolve the store so a missing `forRoot()` fails at boot,\n * not on the first throttled request. Also registers a per-app marker\n * value so ThrottleMiddleware can distinguish \"module imported into this\n * app\" from \"module class loaded somewhere in the process\" (the latter is\n * indistinguishable at the DI layer because @Module's `registry()` call\n * binds providers globally at decoration time).\n */\n onInitialize({ container }: ModuleContext): void {\n container.resolve<IRateLimiterStore>(RATE_LIMITER_TOKENS.Store)\n container.registerValue(RATE_LIMITER_TOKENS.ModuleMarker, { imported: true })\n }\n\n /**\n * Inject `Retry-After` + `X-RateLimit-*` headers on every 429 response.\n * The body itself is rendered by `ExceptionHandler.defaultRender` —\n * content-negotiated, so HTML clients (browsers, Inertia) and JSON\n * clients both get the right shape.\n */\n onException(handler: ExceptionHandler): void {\n handler.dontReport([TooManyRequestsError])\n handler.respond((response, error) => {\n if (!(error instanceof TooManyRequestsError)) return response\n response.headers.set('Retry-After', String(error.info.retryAfter))\n response.headers.set('X-RateLimit-Limit', String(error.info.limit))\n response.headers.set('X-RateLimit-Remaining', '0')\n response.headers.set('X-RateLimit-Reset', String(Math.ceil(error.info.resetAt / 1000)))\n return response\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,QAAb,MAAa,MAAM;CAKC;CACA;CACA;CANlB;CACA;CAEA,YACE,eACA,KACA,WAA2B,OAC3B;EAHgB,KAAA,gBAAA;EACA,KAAA,MAA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,OAAO;GACjE,QAAQ,CAAC,oBAAoB,YAAY;EAC3C;CACF;AACF,CAAC,CAAA,GAAA,iBAAA"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/rate-limiter/limit.ts","../../src/rate-limiter/rate-limiter-registry.ts","../../src/rate-limiter/stores/kv-store.ts","../../src/rate-limiter/stores/memory-store.ts","../../src/rate-limiter/stores/store-factory.ts","../../src/rate-limiter/rate-limiter.module.ts"],"sourcesContent":["import type { RouterContext } from '../router/router-context'\n\n/**\n * Standard rate-limit response headers passed to custom response handlers.\n * Keys are canonical HTTP header names; values are the stringified counts.\n */\nexport interface RateLimitHeaders {\n 'Retry-After': string\n 'X-RateLimit-Limit': string\n 'X-RateLimit-Remaining': string\n 'X-RateLimit-Reset': string\n}\n\n/**\n * Custom response handler invoked when a limit is exceeded and the user\n * supplied `.response()` on the {@link Limit}. Receives the request context\n * and the precomputed standard headers (which the handler can spread, drop,\n * or override).\n */\nexport type RateLimitResponseHandler = (\n ctx: RouterContext,\n headers: RateLimitHeaders,\n) => Response | Promise<Response>\n\n/**\n * A single rate limit window.\n *\n * Build via the static factories (`perSecond`, `perMinute`, `perMinutes`,\n * `perHour`, `perDay`, `none`). Chain `.by(key)` to scope per-actor and\n * `.response(handler)` to override the default 429 response.\n *\n * Returned (singly or as an array) by limiter resolvers registered via\n * `RateLimiterRegistry.for()`.\n *\n * @example\n * ```typescript\n * Limit.perMinute(60).by(ctx.header('cf-connecting-ip') ?? 'global')\n * Limit.perHour(100).by(userId)\n * Limit.none() // bypass\n * ```\n */\nexport class Limit {\n private _key?: string\n private _customResponse?: RateLimitResponseHandler\n\n private constructor(\n public readonly windowSeconds: number,\n public readonly max: number,\n public readonly disabled = false,\n ) {}\n\n static perSecond(max: number): Limit {\n return new Limit(1, max)\n }\n\n static perSeconds(seconds: number, max: number): Limit {\n return new Limit(seconds, max)\n }\n\n static perMinute(max: number): Limit {\n return new Limit(60, max)\n }\n\n static perMinutes(minutes: number, max: number): Limit {\n return new Limit(minutes * 60, max)\n }\n\n static perHour(max: number): Limit {\n return new Limit(60 * 60, max)\n }\n\n static perDay(max: number): Limit {\n return new Limit(24 * 60 * 60, max)\n }\n\n /** Bypass the limiter entirely for this request. */\n static none(): Limit {\n return new Limit(0, 0, true)\n }\n\n /** Scope this limit to a specific actor (user id, IP, tenant, etc.). */\n by(key: string | number): this {\n this._key = String(key)\n return this\n }\n\n /**\n * Override the default 429 response. The handler receives the standard\n * `RateLimitHeaders` so it can spread them onto its own Response or omit\n * them as it sees fit.\n */\n response(handler: RateLimitResponseHandler): this {\n this._customResponse = handler\n return this\n }\n\n get key(): string | undefined {\n return this._key\n }\n\n get customResponse(): RateLimitResponseHandler | undefined {\n return this._customResponse\n }\n}\n","import { type Container, DI_TOKENS, inject } from '../di'\nimport { Singleton } from '../di/decorators'\nimport { Macroable } from '../macroable'\nimport type { Next } from '../router/middleware.interface'\nimport type { RouterContext } from '../router/router-context'\nimport { RateLimiterError, TooManyRequestsError } from './errors'\nimport type { Limit, RateLimitHeaders } from './limit'\nimport { RATE_LIMITER_TOKENS } from './rate-limiter.tokens'\nimport type { IRateLimiterStore, RateLimitHit } from './stores/rate-limiter-store.interface'\n\n/**\n * Resolver function registered via {@link RateLimiterRegistry.for}. Receives\n * the request context and returns the limit (or limits) that apply to this\n * request. Return `Limit.none()` to bypass for the current request.\n */\nexport type LimitResolver = (\n ctx: RouterContext,\n) => Limit | Limit[] | Promise<Limit | Limit[]>\n\ninterface StoredHit {\n count: number\n resetAt: number\n}\n\n/**\n * Central registry of named rate limiters and the request-time enforcement\n * pipeline. Resolved as a singleton; consumed by `ThrottleMiddleware`.\n *\n * Register limiters in a module's `onInitialize` hook:\n * ```typescript\n * @Module({})\n * export class RateLimitsModule implements OnInitialize {\n * onInitialize({ container }: ModuleContext): void {\n * const limiter = container.resolve<RateLimiterRegistry>(RATE_LIMITER_TOKENS.Registry)\n * limiter.for('api', (ctx) => Limit.perMinute(60).by(ctx.header('cf-connecting-ip') ?? '*'))\n * }\n * }\n * ```\n *\n * Extensible via `Macroable`: adapter packages (e.g. `@stratal/framework/auth`)\n * can attach extra registration methods such as `forPath()` for better-auth\n * `customRules` interop.\n */\n// IMPORTANT: do not pass a token to @Singleton — that would self-register\n// the class globally at module-load time, making the Registry resolvable\n// even when the user never imported RateLimiterModule. We rely on\n// RateLimiterModule providers being the only binding source, so\n// `{ isOptional: true }` in ThrottleMiddleware correctly returns undefined\n// when the module is missing.\n@Singleton()\nexport class RateLimiterRegistry extends Macroable {\n private readonly resolvers = new Map<string, LimitResolver>()\n\n constructor(\n @inject(DI_TOKENS.Container) private readonly container: Container,\n ) {\n super()\n }\n\n /**\n * Resolve the store per access instead of capturing it at construction.\n * The registry is a singleton built during module init; lazy resolution\n * keeps later `RATE_LIMITER_TOKENS.Store` overrides (e.g. the testing\n * harness disabling limits) effective.\n */\n private get store(): IRateLimiterStore {\n return this.container.resolve<IRateLimiterStore>(RATE_LIMITER_TOKENS.Store)\n }\n\n /**\n * Register a named limiter. Names must be unique; calling `for()` again\n * with the same name overwrites the previous resolver (matches Laravel\n * `RateLimiter::for` semantics — last definition wins).\n */\n for(name: string, resolver: LimitResolver): void {\n this.resolvers.set(name, resolver)\n }\n\n has(name: string): boolean {\n return this.resolvers.has(name)\n }\n\n /**\n * Enforce the named limiter for the current request. Called by\n * `ThrottleMiddleware` (the per-name class produced by\n * `createThrottleMiddleware`). Resolves the limiter, increments the store\n * for each non-bypassed limit, sets `X-RateLimit-*` headers on success, and\n * either invokes the limit's custom `.response()` or throws\n * {@link TooManyRequestsError} when a limit is exceeded.\n */\n async handle(name: string, ctx: RouterContext, next: Next): Promise<Response | void> {\n const resolver = this.resolvers.get(name)\n if (!resolver) {\n throw new RateLimiterError(`Rate limiter \"${name}\" is not defined. Register it with limiter.for(\"${name}\", ...) in a module's onInitialize hook.`)\n }\n\n const resolved = await resolver(ctx)\n const limits = Array.isArray(resolved) ? resolved : [resolved]\n const active = limits.filter((l) => !l.disabled)\n\n if (active.length === 0) {\n return next()\n }\n\n let mostRestrictive: { limit: Limit; remaining: number; resetAt: number } | undefined\n let exceeded: { limit: Limit; resetAt: number } | undefined\n\n for (const limit of active) {\n const key = this.makeKey(name, limit.windowSeconds, limit.key)\n const hit = await this.hit(key, limit.windowSeconds)\n\n if (hit.count > limit.max) {\n if (!exceeded || hit.resetAt > exceeded.resetAt) {\n exceeded = { limit, resetAt: hit.resetAt }\n }\n continue\n }\n\n const remaining = limit.max - hit.count\n if (!mostRestrictive || remaining < mostRestrictive.remaining) {\n mostRestrictive = { limit, remaining, resetAt: hit.resetAt }\n }\n }\n\n if (exceeded) {\n const headers = this.makeHeaders(exceeded.limit.max, 0, exceeded.resetAt)\n if (exceeded.limit.customResponse) {\n return exceeded.limit.customResponse(ctx, headers)\n }\n throw new TooManyRequestsError({\n retryAfter: Number(headers['Retry-After']),\n limit: exceeded.limit.max,\n resetAt: exceeded.resetAt,\n })\n }\n\n await next()\n\n if (mostRestrictive) {\n const headers = this.makeHeaders(\n mostRestrictive.limit.max,\n mostRestrictive.remaining,\n mostRestrictive.resetAt,\n )\n // Hono populates ctx.c.res after next() — same pattern as logger.middleware.ts.\n const downstream = ctx.c.res\n downstream.headers.set('X-RateLimit-Limit', headers['X-RateLimit-Limit'])\n downstream.headers.set('X-RateLimit-Remaining', headers['X-RateLimit-Remaining'])\n downstream.headers.set('X-RateLimit-Reset', headers['X-RateLimit-Reset'])\n }\n }\n\n /**\n * Get-modify-set increment over the typed KV store. Not atomic across\n * concurrent edge requests on KV — see `KvRateLimiterStore`'s caveat.\n */\n private async hit(key: string, windowSeconds: number): Promise<RateLimitHit> {\n const now = Date.now()\n const existing = await this.store.get<StoredHit>(key)\n\n let next: StoredHit\n if (!existing || existing.resetAt <= now) {\n next = { count: 1, resetAt: now + windowSeconds * 1000 }\n } else {\n next = { count: existing.count + 1, resetAt: existing.resetAt }\n }\n\n const ttlSeconds = Math.max(1, Math.ceil((next.resetAt - now) / 1000))\n await this.store.set(key, next, ttlSeconds)\n return next\n }\n\n private makeKey(name: string, windowSeconds: number, by: string | undefined): string {\n const actor = by ?? '*'\n return `rl:${name}:${windowSeconds}:${actor}`\n }\n\n private makeHeaders(limit: number, remaining: number, resetAt: number): RateLimitHeaders {\n const retryAfter = Math.max(1, Math.ceil((resetAt - Date.now()) / 1000))\n return {\n 'Retry-After': String(retryAfter),\n 'X-RateLimit-Limit': String(limit),\n 'X-RateLimit-Remaining': String(Math.max(0, remaining)),\n 'X-RateLimit-Reset': String(Math.ceil(resetAt / 1000)),\n }\n }\n}\n","import type { CacheService } from '../../cache/services/cache.service'\nimport type { IRateLimiterStore } from './rate-limiter-store.interface'\n\n/**\n * Cloudflare KV-backed typed KV store.\n *\n * KV's minimum `expirationTtl` is 60 seconds; sub-60s windows are still\n * enforced by the registry's algorithm via the persisted `resetAt`, but\n * the key itself may live in KV longer than the logical window.\n *\n * KV has no native atomic increment, so concurrent writes from different\n * edge locations may undercount under high contention. That's an inherent\n * KV tradeoff — pick `{ useClass: MyDurableObjectStore }` for strict\n * accuracy across edges.\n */\nexport class KvRateLimiterStore implements IRateLimiterStore {\n constructor(private readonly cache: CacheService) {}\n\n async get<T>(key: string): Promise<T | null> {\n return (await this.cache.get<T>(key, 'json')) ?? null\n }\n\n async set<T>(key: string, value: T, ttlSeconds: number): Promise<void> {\n const ttl = Math.max(60, Math.ceil(ttlSeconds))\n await this.cache.put(key, JSON.stringify(value), { expirationTtl: ttl })\n }\n\n async delete(key: string): Promise<void> {\n await this.cache.delete(key)\n }\n}\n","import type { IRateLimiterStore } from './rate-limiter-store.interface'\n\ninterface Entry {\n value: unknown\n expiresAt: number\n}\n\n/**\n * In-process Map-backed typed KV store.\n *\n * Suitable for tests and single-isolate scenarios. Not safe across\n * Cloudflare Worker isolates — entries reset whenever a fresh isolate\n * spins up. Use `KvRateLimiterStore` (or a custom Durable Object store)\n * for production. Expiry is lazy: stale entries are dropped on the next\n * `get`.\n */\nexport class InMemoryRateLimiterStore implements IRateLimiterStore {\n private readonly entries = new Map<string, Entry>()\n\n get<T>(key: string): Promise<T | null> {\n const entry = this.entries.get(key)\n if (!entry) return Promise.resolve(null)\n if (entry.expiresAt <= Date.now()) {\n this.entries.delete(key)\n return Promise.resolve(null)\n }\n return Promise.resolve(entry.value as T)\n }\n\n set<T>(key: string, value: T, ttlSeconds: number): Promise<void> {\n this.entries.set(key, { value, expiresAt: Date.now() + ttlSeconds * 1000 })\n return Promise.resolve()\n }\n\n delete(key: string): Promise<void> {\n this.entries.delete(key)\n return Promise.resolve()\n }\n}\n","import { inject } from '../../di'\nimport { CACHE_TOKENS } from '../../cache/cache.tokens'\nimport type { CacheService } from '../../cache/services/cache.service'\nimport { CONTAINER_TOKEN, type Container } from '../../di'\nimport { Singleton } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport type { StratalEnv } from '../../env'\nimport type { Constructor } from '../../types'\nimport { RateLimiterError } from '../errors'\nimport { RATE_LIMITER_TOKENS } from '../rate-limiter.tokens'\nimport { KvRateLimiterStore } from './kv-store'\nimport { InMemoryRateLimiterStore } from './memory-store'\nimport type { IRateLimiterStore } from './rate-limiter-store.interface'\n\n/**\n * Configuration for `RateLimiterModule.forRoot()`. Picks the backing store.\n *\n * - `'kv'`: Cloudflare KV. `binding` names the KVNamespace on `StratalEnv`.\n * - `'memory'`: in-process Map. Tests / single-isolate only.\n * - `{ useClass }`: any class implementing `IRateLimiterStore`. Resolved\n * from the DI container (so the class can declare its own `@inject` deps,\n * e.g. a Durable Object namespace from `StratalEnv`).\n */\nexport type RateLimiterModuleOptions =\n | { store: 'kv'; binding: keyof StratalEnv }\n | { store: 'memory' }\n | { store: { useClass: Constructor<IRateLimiterStore> } }\n\n// IMPORTANT: see RateLimiterRegistry — no token on @Singleton so the\n// factory isn't globally bound at class-load time. Module providers are\n// the sole binding source, which keeps the \"module not imported\" detection\n// in ThrottleMiddleware working.\n@Singleton()\nexport class RateLimiterStoreFactory {\n constructor(\n @inject(DI_TOKENS.CloudflareEnv) private readonly env: StratalEnv,\n @inject(CACHE_TOKENS.CacheService) private readonly cache: CacheService,\n @inject(CONTAINER_TOKEN) private readonly container: Container,\n @inject(RATE_LIMITER_TOKENS.Options, { isOptional: true })\n private readonly options?: RateLimiterModuleOptions,\n ) {}\n\n create(): IRateLimiterStore {\n if (!this.options) {\n throw new RateLimiterError('RateLimiterModule is not configured. Call RateLimiterModule.forRoot({ store: ... }) to configure a backing store.')\n }\n\n const { store } = this.options\n\n if (store === 'memory') {\n return new InMemoryRateLimiterStore()\n }\n\n if (store === 'kv') {\n const binding = this.env[this.options.binding] as KVNamespace | undefined\n if (!binding) {\n throw new RateLimiterError(`KV binding \"${String(this.options.binding)}\" is not available in the environment.`)\n }\n return new KvRateLimiterStore(this.cache.withBinding(binding))\n }\n\n return this.container.resolve<IRateLimiterStore>(store.useClass)\n }\n}\n","import { CacheModule } from '../cache'\nimport type { ExceptionHandler } from '../errors/exception-handler'\nimport { Module } from '../module'\nimport type { AsyncModuleOptions, DynamicModule, ModuleContext, OnException, OnInitialize } from '../module/types'\nimport { TooManyRequestsError } from './errors'\nimport { RateLimiterRegistry } from './rate-limiter-registry'\nimport { RATE_LIMITER_TOKENS } from './rate-limiter.tokens'\nimport { RateLimiterStoreFactory, type RateLimiterModuleOptions } from './stores/store-factory'\nimport type { IRateLimiterStore } from './stores/rate-limiter-store.interface'\n\n/**\n * Rate limiter module — opt-in, NOT registered automatically by Application.\n *\n * Usage:\n * ```typescript\n * @Module({\n * imports: [RateLimiterModule.forRoot({ store: 'kv', binding: 'RATE_LIMITS' })],\n * })\n * export class AppModule {}\n * ```\n *\n * Define limiters in any module's `onInitialize` hook by resolving\n * `RATE_LIMITER_TOKENS.Registry` from the container. Apply them with\n * `router.throttle('name')` or `@RateLimit('name')`.\n *\n * The module:\n * - eagerly validates the store at app boot (`onInitialize` resolves the\n * factory and calls `create()`); a missing `forRoot` surfaces\n * `RateLimiterError` before any request is served.\n * - registers a `respond()` callback on the `ExceptionHandler` (via\n * `onException`) that injects `Retry-After` and `X-RateLimit-*` headers\n * on every {@link TooManyRequestsError} response, regardless of whether\n * the body was rendered as JSON, HTML, or via Inertia.\n */\n@Module({\n imports: [CacheModule],\n providers: [\n { provide: RATE_LIMITER_TOKENS.Registry, useClass: RateLimiterRegistry },\n { provide: RATE_LIMITER_TOKENS.StoreFactory, useClass: RateLimiterStoreFactory },\n {\n provide: RATE_LIMITER_TOKENS.Store,\n useFactory: (factory: RateLimiterStoreFactory) => factory.create(),\n inject: [RATE_LIMITER_TOKENS.StoreFactory],\n },\n ],\n})\nexport class RateLimiterModule implements OnInitialize, OnException {\n /**\n * Configure the rate limiter with a store choice.\n *\n * @param options - `{ store: 'kv', binding }` | `{ store: 'memory' }` | `{ store: { useClass } }`\n */\n static forRoot(options: RateLimiterModuleOptions): DynamicModule {\n return {\n module: RateLimiterModule,\n providers: [\n { provide: RATE_LIMITER_TOKENS.Options, useValue: options },\n ],\n }\n }\n\n /**\n * Async configuration. Use when store options depend on other services\n * (e.g. ConfigService).\n */\n static forRootAsync(options: AsyncModuleOptions<RateLimiterModuleOptions>): DynamicModule {\n return {\n module: RateLimiterModule,\n providers: [\n {\n provide: RATE_LIMITER_TOKENS.Options,\n useFactory: options.useFactory,\n inject: options.inject,\n },\n ],\n }\n }\n\n /**\n * Eagerly resolve the store so a missing `forRoot()` fails at boot,\n * not on the first throttled request. Also registers a per-app marker\n * value so ThrottleMiddleware can distinguish \"module imported into this\n * app\" from \"module class loaded somewhere in the process\" (the latter is\n * indistinguishable at the DI layer because @Module's `registry()` call\n * binds providers globally at decoration time).\n */\n onInitialize({ container }: ModuleContext): void {\n container.resolve<IRateLimiterStore>(RATE_LIMITER_TOKENS.Store)\n container.registerValue(RATE_LIMITER_TOKENS.ModuleMarker, { imported: true })\n }\n\n /**\n * Inject `Retry-After` + `X-RateLimit-*` headers on every 429 response.\n * The body itself is rendered by `ExceptionHandler.defaultRender` —\n * content-negotiated, so HTML clients (browsers, Inertia) and JSON\n * clients both get the right shape.\n */\n onException(handler: ExceptionHandler): void {\n handler.dontReport([TooManyRequestsError])\n handler.respond((response, error) => {\n if (!(error instanceof TooManyRequestsError)) return response\n response.headers.set('Retry-After', String(error.info.retryAfter))\n response.headers.set('X-RateLimit-Limit', String(error.info.limit))\n response.headers.set('X-RateLimit-Remaining', '0')\n response.headers.set('X-RateLimit-Reset', String(Math.ceil(error.info.resetAt / 1000)))\n return response\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,QAAb,MAAa,MAAM;CAKC;CACA;CACA;CANlB;CACA;CAEA,YACE,eACA,KACA,WAA2B,OAC3B;EAHgB,KAAA,gBAAA;EACA,KAAA,MAAA;EACA,KAAA,WAAA;CACf;CAEH,OAAO,UAAU,KAAoB;EACnC,OAAO,IAAI,MAAM,GAAG,GAAG;CACzB;CAEA,OAAO,WAAW,SAAiB,KAAoB;EACrD,OAAO,IAAI,MAAM,SAAS,GAAG;CAC/B;CAEA,OAAO,UAAU,KAAoB;EACnC,OAAO,IAAI,MAAM,IAAI,GAAG;CAC1B;CAEA,OAAO,WAAW,SAAiB,KAAoB;EACrD,OAAO,IAAI,MAAM,UAAU,IAAI,GAAG;CACpC;CAEA,OAAO,QAAQ,KAAoB;EACjC,OAAO,IAAI,MAAM,MAAS,GAAG;CAC/B;CAEA,OAAO,OAAO,KAAoB;EAChC,OAAO,IAAI,MAAM,OAAU,IAAI,GAAG;CACpC;;CAGA,OAAO,OAAc;EACnB,OAAO,IAAI,MAAM,GAAG,GAAG,IAAI;CAC7B;;CAGA,GAAG,KAA4B;EAC7B,KAAK,OAAO,OAAO,GAAG;EACtB,OAAO;CACT;;;;;;CAOA,SAAS,SAAyC;EAChD,KAAK,kBAAkB;EACvB,OAAO;CACT;CAEA,IAAI,MAA0B;EAC5B,OAAO,KAAK;CACd;CAEA,IAAI,iBAAuD;EACzD,OAAO,KAAK;CACd;AACF;;;ACrDO,IAAA,sBAAA,MAAM,4B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,UAAU;GACnC,IAAI,EAAE,iBAAiB,uBAAuB,OAAO;GACrD,SAAS,QAAQ,IAAI,eAAe,OAAO,MAAM,KAAK,UAAU,CAAC;GACjE,SAAS,QAAQ,IAAI,qBAAqB,OAAO,MAAM,KAAK,KAAK,CAAC;GAClE,SAAS,QAAQ,IAAI,yBAAyB,GAAG;GACjD,SAAS,QAAQ,IAAI,qBAAqB,OAAO,KAAK,KAAK,MAAM,KAAK,UAAU,GAAI,CAAC,CAAC;GACtF,OAAO;EACT,CAAC;CACH;AACF;qDA1EC,OAAO;CACN,SAAS,CAAC,WAAW;CACrB,WAAW;EACT;GAAE,SAAS,oBAAoB;GAAU,UAAU;EAAoB;EACvE;GAAE,SAAS,oBAAoB;GAAc,UAAU;EAAwB;EAC/E;GACE,SAAS,oBAAoB;GAC7B,aAAa,YAAqC,QAAQ,OAAO;GACjE,QAAQ,CAAC,oBAAoB,YAAY;EAC3C;CACF;AACF,CAAC,CAAA,GAAA,iBAAA"}
|
package/dist/{route-registration.service-HN8WgIis.mjs → route-registration.service-CDPQKpm4.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-BBjsoOtd.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { b as ROUTER_TOKENS, g as getMethodInjections, l as Singleton, p as inject, r as DI_TOKENS } from "./di-D7qmrAir.mjs";
|
|
3
3
|
import { n as getMetadata, t as defineMetadata } from "./metadata-DzzprcID.mjs";
|
|
4
4
|
import { n as __decorateParam, t as __decorate } from "./decorate-CuAoSZvs.mjs";
|
|
5
5
|
import { LOGGER_TOKENS } from "./logger/index.mjs";
|
|
6
|
-
import { d as
|
|
7
|
-
import { a as RouterContext, c as METHOD_STATUS_CODES, d as SECURITY_SCHEMES, l as ROUTER_CONTEXT_KEYS, o as DEFAULT_CONTENT_TYPE, s as HTTP_METHODS, u as ROUTE_METADATA_KEYS } from "./exception-context-
|
|
8
|
-
import { o as RouterError, s as createThrottleMiddleware } from "./module-registry-
|
|
6
|
+
import { d as HttpException, f as abort } from "./errors-C01O2T-n.mjs";
|
|
7
|
+
import { a as RouterContext, c as METHOD_STATUS_CODES, d as SECURITY_SCHEMES, l as ROUTER_CONTEXT_KEYS, o as DEFAULT_CONTENT_TYPE, s as HTTP_METHODS, u as ROUTE_METADATA_KEYS } from "./exception-context-D-kvney-.mjs";
|
|
8
|
+
import { o as RouterError, s as createThrottleMiddleware } from "./module-registry-NxX5O0Qk.mjs";
|
|
9
9
|
import { i as zod_exports, r as z } from "./zod-eKqqhZ5_.mjs";
|
|
10
|
-
import { n as getControllerOptions, r as getControllerRoute } from "./controller.decorator-
|
|
11
|
-
import "./http-method.decorator-
|
|
10
|
+
import { n as getControllerOptions, r as getControllerRoute } from "./controller.decorator-YSTPQntu.mjs";
|
|
11
|
+
import "./http-method.decorator-BljM8BDj.mjs";
|
|
12
12
|
import { i as getMethodGuards, r as getControllerGuards, t as GuardExecutionService } from "./guards-DALPXy3_.mjs";
|
|
13
|
-
import { n as getRateLimits } from "./rate-limit.decorator-
|
|
14
|
-
import { a as getWsOnCloseMethod, o as getWsOnErrorMethod, s as getWsOnMessageMethod, t as GatewayContext, u as isGateway } from "./gateway-context-
|
|
13
|
+
import { n as getRateLimits } from "./rate-limit.decorator-Djs4oYDB.mjs";
|
|
14
|
+
import { a as getWsOnCloseMethod, o as getWsOnErrorMethod, s as getWsOnMessageMethod, t as GatewayContext, u as isGateway } from "./gateway-context-m7kEzRa2.mjs";
|
|
15
15
|
import { o as toOpenAPIPath, r as generateConventionRouteName, s as toRoutingOpenAPIPath } from "./route-name-DGoBOfPg.mjs";
|
|
16
16
|
//#region src/router/errors/route-not-found.error.ts
|
|
17
17
|
var RouteNotFoundError = class extends HttpException {
|
|
@@ -915,4 +915,4 @@ RouteRegistrationService = __decorate([
|
|
|
915
915
|
//#endregion
|
|
916
916
|
export { ResponseValidationError as _, paginatedResponseSchema as a, uuidParamSchema as c, getRouteDecoratedMethods as d, getRouteMetadata as f, InvalidSignatureError as g, parseDomainPattern as h, errorResponseSchema as i, validationErrorResponseSchema as l, createDomainMiddleware as m, route_registration_service_exports as n, paginationQuerySchema as o, createMiddlewareChain as p, commonErrorSchemas as r, successMessageSchema as s, RouteRegistrationService as t, Route as u, SchemaValidationError as v, RouteNotFoundError as y };
|
|
917
917
|
|
|
918
|
-
//# sourceMappingURL=route-registration.service-
|
|
918
|
+
//# sourceMappingURL=route-registration.service-CDPQKpm4.mjs.map
|