Skip to content

Commit 10a1c4a

Browse files
[wrangler] Allow deleting KV namespaces by name (#12464)
1 parent d06ad09 commit 10a1c4a

File tree

8 files changed

+275
-100
lines changed

8 files changed

+275
-100
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Allow deleting KV namespaces by name
6+
7+
You can now delete a KV namespace by providing its name as a positional argument:
8+
9+
```bash
10+
wrangler kv namespace delete my-namespace
11+
```
12+
13+
This aligns the delete command with the create command, which also accepts a namespace name.
14+
The existing `--namespace-id` and `--binding` flags continue to work as before.

packages/wrangler/src/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe("wrangler", () => {
287287
COMMANDS
288288
wrangler kv namespace create <namespace> Create a new namespace
289289
wrangler kv namespace list Output a list of all KV namespaces associated with your account id
290-
wrangler kv namespace delete Delete a given namespace.
290+
wrangler kv namespace delete [namespace] Delete a given namespace.
291291
wrangler kv namespace rename [old-name] Rename a KV namespace
292292
293293
GLOBAL FLAGS

packages/wrangler/src/__tests__/kv/bulk.test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe("kv", () => {
325325
const keys = ["someKey1", "ns:someKey2"];
326326
writeFileSync("./keys.json", JSON.stringify(keys));
327327
mockConfirm({
328-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
328+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
329329
result: true,
330330
});
331331
const requests = mockDeleteRequest("some-namespace-id", keys);
@@ -349,7 +349,7 @@ describe("kv", () => {
349349
const keys = [{ name: "someKey1" }, { name: "ns:someKey2" }];
350350
writeFileSync("./keys.json", JSON.stringify(keys));
351351
mockConfirm({
352-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
352+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
353353
result: true,
354354
});
355355
const requests = mockDeleteRequest(
@@ -376,7 +376,7 @@ describe("kv", () => {
376376
const keys = new Array(12000).fill("some-key");
377377
writeFileSync("./keys.json", JSON.stringify(keys));
378378
mockConfirm({
379-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
379+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
380380
result: true,
381381
});
382382
const requests = mockDeleteRequest("some-namespace-id", keys);
@@ -413,7 +413,7 @@ describe("kv", () => {
413413
const keys = ["someKey1", "ns:someKey2"];
414414
writeFileSync("./keys.json", JSON.stringify(keys));
415415
mockConfirm({
416-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
416+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
417417
result: false,
418418
});
419419
await runWrangler(
@@ -477,55 +477,55 @@ describe("kv", () => {
477477
const keys = 12354;
478478
writeFileSync("./keys.json", JSON.stringify(keys));
479479
mockConfirm({
480-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
480+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
481481
result: true,
482482
});
483483
await expect(
484484
runWrangler(
485485
`kv bulk delete --remote --namespace-id some-namespace-id keys.json`
486486
)
487487
).rejects.toThrowErrorMatchingInlineSnapshot(`
488-
[Error: Unexpected JSON input from "keys.json".
489-
Expected an array of strings but got:
490-
12354]
488+
[Error: Unexpected JSON input from "keys.json".
489+
Expected an array of strings but got:
490+
12354]
491491
`);
492492
expect(std.out).toMatchInlineSnapshot(`
493-
"
494-
⛅️ wrangler x.x.x
495-
──────────────────
496-
Resource location: remote
493+
"
494+
⛅️ wrangler x.x.x
495+
──────────────────
496+
Resource location: remote
497497
498-
"
499-
`);
498+
"
499+
`);
500500
expect(std.warn).toMatchInlineSnapshot(`""`);
501501
});
502502

503503
it("should error if the file contains non-string items", async () => {
504504
const keys = ["good", 12354, { key: "someKey" }, null];
505505
writeFileSync("./keys.json", JSON.stringify(keys));
506506
mockConfirm({
507-
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
507+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
508508
result: true,
509509
});
510510
await expect(
511511
runWrangler(
512512
`kv bulk delete --remote --namespace-id some-namespace-id keys.json`
513513
)
514514
).rejects.toThrowErrorMatchingInlineSnapshot(`
515-
[Error: Unexpected JSON input from "keys.json".
516-
Expected an array of strings or objects with a "name" key.
517-
The item at index 1 is type: "number" - 12354
518-
The item at index 2 is type: "object" - {"key":"someKey"}
519-
The item at index 3 is type: "object" - null]
520-
`);
515+
[Error: Unexpected JSON input from "keys.json".
516+
Expected an array of strings or objects with a "name" key.
517+
The item at index 1 is type: "number" - 12354
518+
The item at index 2 is type: "object" - {"key":"someKey"}
519+
The item at index 3 is type: "object" - null]
520+
`);
521521
expect(std.out).toMatchInlineSnapshot(`
522-
"
523-
⛅️ wrangler x.x.x
524-
──────────────────
525-
Resource location: remote
522+
"
523+
⛅️ wrangler x.x.x
524+
──────────────────
525+
Resource location: remote
526526
527-
"
528-
`);
527+
"
528+
`);
529529
expect(std.warn).toMatchInlineSnapshot(`""`);
530530
});
531531
});

packages/wrangler/src/__tests__/kv/key.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe("kv", () => {
101101
──────────────────
102102
Resource location: remote
103103
104-
Writing the value "my-value" to key "my-key" on namespace some-namespace-id."
104+
Writing the value "my-value" to key "my-key" on namespace id: "some-namespace-id"."
105105
`
106106
);
107107
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -125,7 +125,7 @@ describe("kv", () => {
125125
──────────────────
126126
Resource location: remote
127127
128-
Writing the value "my-value" to key "/my-key" on namespace DS9."
128+
Writing the value "my-value" to key "/my-key" on namespace id: "DS9"."
129129
`
130130
);
131131
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -148,7 +148,7 @@ describe("kv", () => {
148148
──────────────────
149149
Resource location: remote
150150
151-
Writing the value "my-value" to key "my-key" on namespace bound-id."
151+
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "bound-id")."
152152
`
153153
);
154154
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -173,7 +173,7 @@ describe("kv", () => {
173173
──────────────────
174174
Resource location: remote
175175
176-
Writing the value "my-value" to key "my-key" on namespace preview-bound-id."
176+
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "preview-bound-id")."
177177
`
178178
);
179179
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -198,7 +198,7 @@ describe("kv", () => {
198198
──────────────────
199199
Resource location: remote
200200
201-
Writing the value "my-value" to key "my-key" on namespace some-namespace-id."
201+
Writing the value "my-value" to key "my-key" on namespace id: "some-namespace-id"."
202202
`
203203
);
204204
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -220,7 +220,7 @@ describe("kv", () => {
220220
──────────────────
221221
Resource location: remote
222222
223-
Writing the value "my-value" to key "my-key" on namespace env-bound-id."
223+
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "env-bound-id")."
224224
`
225225
);
226226
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -244,7 +244,7 @@ describe("kv", () => {
244244
──────────────────
245245
Resource location: remote
246246
247-
Writing the contents of foo.txt to the key "my-key" on namespace some-namespace-id."
247+
Writing the contents of foo.txt to the key "my-key" on namespace id: "some-namespace-id"."
248248
`
249249
);
250250
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -271,7 +271,7 @@ describe("kv", () => {
271271
──────────────────
272272
Resource location: remote
273273
274-
Writing the contents of test.png to the key "my-key" on namespace another-namespace-id."
274+
Writing the contents of test.png to the key "my-key" on namespace id: "another-namespace-id"."
275275
`
276276
);
277277
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -297,7 +297,7 @@ describe("kv", () => {
297297
──────────────────
298298
Resource location: remote
299299
300-
Writing the value "dVal" to key "dKey" on namespace some-namespace-id with metadata "{"mKey":"mValue"}"."
300+
Writing the value "dVal" to key "dKey" on namespace id: "some-namespace-id" with metadata "{"mKey":"mValue"}"."
301301
`
302302
);
303303
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -327,7 +327,7 @@ describe("kv", () => {
327327
──────────────────
328328
Resource location: remote
329329
330-
Writing the contents of test.png to the key "another-my-key" on namespace some-namespace-id with metadata "{"mKey":"mValue"}"."
330+
Writing the contents of test.png to the key "another-my-key" on namespace id: "some-namespace-id" with metadata "{"mKey":"mValue"}"."
331331
`
332332
);
333333
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -1232,7 +1232,7 @@ describe("kv", () => {
12321232
──────────────────
12331233
Resource location: remote
12341234
1235-
Deleting the key "/NCC-74656" on namespace voyager."
1235+
Deleting the key "/NCC-74656" on namespace id: "voyager"."
12361236
`
12371237
);
12381238
expect(std.err).toMatchInlineSnapshot(`""`);
@@ -1284,7 +1284,7 @@ describe("kv", () => {
12841284
──────────────────
12851285
Resource location: remote
12861286
1287-
Deleting the key "someKey" on namespace env-bound-id."
1287+
Deleting the key "someKey" on namespace binding: "someBinding" (id: "env-bound-id")."
12881288
`
12891289
);
12901290
expect(std.err).toMatchInlineSnapshot(`""`);

packages/wrangler/src/__tests__/kv/local.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("kv", () => {
2828
2929
Use --remote if you want to access the remote instance.
3030
31-
Writing the value "value" to key "val" on namespace some-namespace-id."
31+
Writing the value "value" to key "val" on namespace id: "some-namespace-id"."
3232
`);
3333

3434
await runWrangler(
@@ -136,7 +136,7 @@ describe("kv", () => {
136136
137137
Use --remote if you want to access the remote instance.
138138
139-
Writing the value "value" to key "val" on namespace some-namespace-id.
139+
Writing the value "value" to key "val" on namespace id: "some-namespace-id".
140140
value"
141141
`);
142142
await runWrangler(`kv key delete val --namespace-id some-namespace-id`);
@@ -148,7 +148,7 @@ describe("kv", () => {
148148
149149
Use --remote if you want to access the remote instance.
150150
151-
Deleting the key "val" on namespace some-namespace-id."
151+
Deleting the key "val" on namespace id: "some-namespace-id"."
152152
`);
153153

154154
await runWrangler(
@@ -401,15 +401,15 @@ describe("kv", () => {
401401
402402
Use --remote if you want to access the remote instance.
403403
404-
Writing the value "value" to key "val" on namespace some-namespace-id.
404+
Writing the value "value" to key "val" on namespace id: "some-namespace-id".
405405
406406
⛅️ wrangler x.x.x
407407
──────────────────
408408
Resource location: local
409409
410410
Use --remote if you want to access the remote instance.
411411
412-
Writing the value "persistValue" to key "val" on namespace some-namespace-id."
412+
Writing the value "persistValue" to key "val" on namespace id: "some-namespace-id"."
413413
`);
414414

415415
await runWrangler(

0 commit comments

Comments
 (0)