Skip to content

Commit 8d1d464

Browse files
authored
feat(wrangler): add ratelimit type generation (#6550)
* feat(wrangler): add ratelimit type generation * add changeset
1 parent 21a09e0 commit 8d1d464

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/poor-books-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feature: add RateLimit type generation to the ratelimit unsafe binding.

packages/wrangler/src/__tests__/type-generation.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ const bindingsConfigMock: Omit<
198198
},
199199
wasm_modules: { MODULE1: "module1.wasm", MODULE2: "module2.wasm" },
200200
unsafe: {
201-
bindings: [{ name: "testing_unsafe", type: "plain_text" }],
201+
bindings: [
202+
{ name: "testing_unsafe", type: "plain_text" },
203+
{ name: "UNSAFE_RATELIMIT", type: "ratelimit" },
204+
],
202205
metadata: { some_key: "some_value" },
203206
},
204207
rules: [
@@ -342,6 +345,7 @@ describe("generateTypes()", () => {
342345
SOME_TEXT_BLOB1: string;
343346
SOME_TEXT_BLOB2: string;
344347
testing_unsafe: any;
348+
UNSAFE_RATELIMIT: RateLimit;
345349
TEST_QUEUE_BINDING: Queue;
346350
SEND_EMAIL_BINDING: SendEmail;
347351
VECTORIZE_BINDING: VectorizeIndex;
@@ -482,6 +486,7 @@ describe("generateTypes()", () => {
482486
export {};
483487
declare global {
484488
const testing_unsafe: any;
489+
const UNSAFE_RATELIMIT: RateLimit;
485490
}
486491
"
487492
`);

packages/wrangler/src/type-generation/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ async function generateTypes(
347347

348348
if (configToDTS.unsafe?.bindings) {
349349
for (const unsafe of configToDTS.unsafe.bindings) {
350-
envTypeStructure.push(constructType(unsafe.name, "any"));
350+
if (unsafe.type === "ratelimit") {
351+
envTypeStructure.push(constructType(unsafe.name, "RateLimit"));
352+
} else {
353+
envTypeStructure.push(constructType(unsafe.name, "any"));
354+
}
351355
}
352356
}
353357

0 commit comments

Comments
 (0)