Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/kv-namespace-delete-by-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"wrangler": minor
---

Allow deleting KV namespaces by name

You can now delete a KV namespace by providing its name as a positional argument:

```bash
wrangler kv namespace delete my-namespace
```

This aligns the delete command with the create command, which also accepts a namespace name.
The existing `--namespace-id` and `--binding` flags continue to work as before.
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe("wrangler", () => {
COMMANDS
wrangler kv namespace create <namespace> Create a new namespace
wrangler kv namespace list Output a list of all KV namespaces associated with your account id
wrangler kv namespace delete Delete a given namespace.
wrangler kv namespace delete [namespace] Delete a given namespace.
wrangler kv namespace rename [old-name] Rename a KV namespace

GLOBAL FLAGS
Expand Down
54 changes: 27 additions & 27 deletions packages/wrangler/src/__tests__/kv/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ describe("kv", () => {
const keys = ["someKey1", "ns:someKey2"];
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: true,
});
const requests = mockDeleteRequest("some-namespace-id", keys);
Expand All @@ -349,7 +349,7 @@ describe("kv", () => {
const keys = [{ name: "someKey1" }, { name: "ns:someKey2" }];
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: true,
});
const requests = mockDeleteRequest(
Expand All @@ -376,7 +376,7 @@ describe("kv", () => {
const keys = new Array(12000).fill("some-key");
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: true,
});
const requests = mockDeleteRequest("some-namespace-id", keys);
Expand Down Expand Up @@ -413,7 +413,7 @@ describe("kv", () => {
const keys = ["someKey1", "ns:someKey2"];
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: false,
});
await runWrangler(
Expand Down Expand Up @@ -477,55 +477,55 @@ describe("kv", () => {
const keys = 12354;
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: true,
});
await expect(
runWrangler(
`kv bulk delete --remote --namespace-id some-namespace-id keys.json`
)
).rejects.toThrowErrorMatchingInlineSnapshot(`
[Error: Unexpected JSON input from "keys.json".
Expected an array of strings but got:
12354]
[Error: Unexpected JSON input from "keys.json".
Expected an array of strings but got:
12354]
`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
Resource location: remote
"
⛅️ wrangler x.x.x
──────────────────
Resource location: remote

"
`);
"
`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});

it("should error if the file contains non-string items", async () => {
const keys = ["good", 12354, { key: "someKey" }, null];
writeFileSync("./keys.json", JSON.stringify(keys));
mockConfirm({
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace id: "some-namespace-id"?`,
result: true,
});
await expect(
runWrangler(
`kv bulk delete --remote --namespace-id some-namespace-id keys.json`
)
).rejects.toThrowErrorMatchingInlineSnapshot(`
[Error: Unexpected JSON input from "keys.json".
Expected an array of strings or objects with a "name" key.
The item at index 1 is type: "number" - 12354
The item at index 2 is type: "object" - {"key":"someKey"}
The item at index 3 is type: "object" - null]
`);
[Error: Unexpected JSON input from "keys.json".
Expected an array of strings or objects with a "name" key.
The item at index 1 is type: "number" - 12354
The item at index 2 is type: "object" - {"key":"someKey"}
The item at index 3 is type: "object" - null]
`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
Resource location: remote
"
⛅️ wrangler x.x.x
──────────────────
Resource location: remote

"
`);
"
`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});
});
Expand Down
24 changes: 12 additions & 12 deletions packages/wrangler/src/__tests__/kv/key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "my-key" on namespace some-namespace-id."
Writing the value "my-value" to key "my-key" on namespace id: "some-namespace-id"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -125,7 +125,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "/my-key" on namespace DS9."
Writing the value "my-value" to key "/my-key" on namespace id: "DS9"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -148,7 +148,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "my-key" on namespace bound-id."
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "bound-id")."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -173,7 +173,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "my-key" on namespace preview-bound-id."
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "preview-bound-id")."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -198,7 +198,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "my-key" on namespace some-namespace-id."
Writing the value "my-value" to key "my-key" on namespace id: "some-namespace-id"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -220,7 +220,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "my-value" to key "my-key" on namespace env-bound-id."
Writing the value "my-value" to key "my-key" on namespace binding: "someBinding" (id: "env-bound-id")."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -244,7 +244,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the contents of foo.txt to the key "my-key" on namespace some-namespace-id."
Writing the contents of foo.txt to the key "my-key" on namespace id: "some-namespace-id"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -271,7 +271,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the contents of test.png to the key "my-key" on namespace another-namespace-id."
Writing the contents of test.png to the key "my-key" on namespace id: "another-namespace-id"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand All @@ -297,7 +297,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the value "dVal" to key "dKey" on namespace some-namespace-id with metadata "{"mKey":"mValue"}"."
Writing the value "dVal" to key "dKey" on namespace id: "some-namespace-id" with metadata "{"mKey":"mValue"}"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -327,7 +327,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Writing the contents of test.png to the key "another-my-key" on namespace some-namespace-id with metadata "{"mKey":"mValue"}"."
Writing the contents of test.png to the key "another-my-key" on namespace id: "some-namespace-id" with metadata "{"mKey":"mValue"}"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -1232,7 +1232,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Deleting the key "/NCC-74656" on namespace voyager."
Deleting the key "/NCC-74656" on namespace id: "voyager"."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down Expand Up @@ -1284,7 +1284,7 @@ describe("kv", () => {
──────────────────
Resource location: remote

Deleting the key "someKey" on namespace env-bound-id."
Deleting the key "someKey" on namespace binding: "someBinding" (id: "env-bound-id")."
`
);
expect(std.err).toMatchInlineSnapshot(`""`);
Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/src/__tests__/kv/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("kv", () => {

Use --remote if you want to access the remote instance.

Writing the value "value" to key "val" on namespace some-namespace-id."
Writing the value "value" to key "val" on namespace id: "some-namespace-id"."
`);

await runWrangler(
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("kv", () => {

Use --remote if you want to access the remote instance.

Writing the value "value" to key "val" on namespace some-namespace-id.
Writing the value "value" to key "val" on namespace id: "some-namespace-id".
value"
`);
await runWrangler(`kv key delete val --namespace-id some-namespace-id`);
Expand All @@ -148,7 +148,7 @@ describe("kv", () => {

Use --remote if you want to access the remote instance.

Deleting the key "val" on namespace some-namespace-id."
Deleting the key "val" on namespace id: "some-namespace-id"."
`);

await runWrangler(
Expand Down Expand Up @@ -401,15 +401,15 @@ describe("kv", () => {

Use --remote if you want to access the remote instance.

Writing the value "value" to key "val" on namespace some-namespace-id.
Writing the value "value" to key "val" on namespace id: "some-namespace-id".

⛅️ wrangler x.x.x
──────────────────
Resource location: local

Use --remote if you want to access the remote instance.

Writing the value "persistValue" to key "val" on namespace some-namespace-id."
Writing the value "persistValue" to key "val" on namespace id: "some-namespace-id"."
`);

await runWrangler(
Expand Down
Loading
Loading