From 47b325af0df87bcf20d922ff385ae9cd21726863 Mon Sep 17 00:00:00 2001 From: Matt DeBoard Date: Wed, 27 Mar 2024 16:21:55 -0500 Subject: [PATCH] Improvements to R2 notification commands (#5416) Change `event-notification` subcmd to `notification` Use `object-{create,delete}`, not `_{delete,create}` Add changeset --- .changeset/yellow-wolves-talk.md | 10 +++++++ packages/wrangler/src/__tests__/r2.test.ts | 32 ++++++++++------------ packages/wrangler/src/r2/helpers.ts | 6 ++-- packages/wrangler/src/r2/index.ts | 4 +-- 4 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 .changeset/yellow-wolves-talk.md diff --git a/.changeset/yellow-wolves-talk.md b/.changeset/yellow-wolves-talk.md new file mode 100644 index 000000000000..80afa7cf08ce --- /dev/null +++ b/.changeset/yellow-wolves-talk.md @@ -0,0 +1,10 @@ +--- +"wrangler": minor +--- + +fix: minor improvements to R2 notification subcommand + +1. `r2 bucket event-notification ` becomes `r2 bucket notification ` +2. Parameters to `--event-type` use `-` instead of `_` (e.g. `object_create` -> `object-create`) + +Since the original command was not yet operational, this update does not constitute a breaking change. diff --git a/packages/wrangler/src/__tests__/r2.test.ts b/packages/wrangler/src/__tests__/r2.test.ts index 3e3c5e0ecdea..a8f3d15642ad 100644 --- a/packages/wrangler/src/__tests__/r2.test.ts +++ b/packages/wrangler/src/__tests__/r2.test.ts @@ -42,11 +42,11 @@ describe("r2", () => { Manage R2 buckets Commands: - wrangler r2 bucket create Create a new R2 bucket - wrangler r2 bucket list List R2 buckets - wrangler r2 bucket delete Delete an R2 bucket - wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket - wrangler r2 bucket event-notification Manage event notifications for an R2 bucket + wrangler r2 bucket create Create a new R2 bucket + wrangler r2 bucket list List R2 buckets + wrangler r2 bucket delete Delete an R2 bucket + wrangler r2 bucket sippy Manage Sippy incremental migration on an R2 bucket + wrangler r2 bucket notification Manage event notifications for an R2 bucket Flags: -j, --experimental-json-config Experimental: Support wrangler.json [boolean] @@ -545,10 +545,10 @@ describe("r2", () => { }); }); - describe("event-notification", () => { + describe("notification", () => { describe("create", () => { it("follows happy path as expected", async () => { - const eventTypes: R2EventType[] = ["object_create", "object_delete"]; + const eventTypes: R2EventType[] = ["object-create", "object-delete"]; const actions: R2EventableOperation[] = []; const bucketName = "my-bucket"; const queue = "my-queue"; @@ -603,7 +603,7 @@ describe("r2", () => { ); await expect( runWrangler( - `r2 bucket event-notification create ${bucketName} --queue ${queue} --event-types ${eventTypes.join( + `r2 bucket notification create ${bucketName} --queue ${queue} --event-types ${eventTypes.join( " " )}` ) @@ -617,15 +617,13 @@ describe("r2", () => { it("errors if required options are not provided", async () => { await expect( - runWrangler( - "r2 bucket event-notification create event-notification-test-001" - ) + runWrangler("r2 bucket notification create notification-test-001") ).rejects.toMatchInlineSnapshot( `[Error: Missing required arguments: event-types, queue]` ); expect(std.out).toMatchInlineSnapshot(` " - wrangler r2 bucket event-notification create + wrangler r2 bucket notification create Create new event notification configuration for an R2 bucket @@ -640,7 +638,7 @@ describe("r2", () => { -v, --version Show version number [boolean] Options: - --event-types, --event-type Specify the kinds of object events to emit notifications for. ex. '--event-types object_create object_delete' [array] [required] [choices: \\"object_create\\", \\"object_delete\\"] + --event-types, --event-type Specify the kinds of object events to emit notifications for. ex. '--event-types object-create object-delete' [array] [required] [choices: \\"object-create\\", \\"object-delete\\"] --prefix only actions on objects with this prefix will emit notifications [string] --suffix only actions on objects with this suffix will emit notifications [string] --queue The name of the queue to which event notifications will be sent. ex '--queue my-queue' [string] [required]" @@ -686,7 +684,7 @@ describe("r2", () => { ); await expect( runWrangler( - `r2 bucket event-notification delete ${bucketName} --queue ${queue}` + `r2 bucket notification delete ${bucketName} --queue ${queue}` ) ).resolves.toBe(undefined); expect(std.out).toMatchInlineSnapshot(` @@ -697,15 +695,13 @@ describe("r2", () => { it("errors if required options are not provided", async () => { await expect( - runWrangler( - "r2 bucket event-notification delete event-notification-test-001" - ) + runWrangler("r2 bucket notification delete notification-test-001") ).rejects.toMatchInlineSnapshot( `[Error: Missing required argument: queue]` ); expect(std.out).toMatchInlineSnapshot(` " - wrangler r2 bucket event-notification delete + wrangler r2 bucket notification delete Delete event notification configuration for an R2 bucket and queue diff --git a/packages/wrangler/src/r2/helpers.ts b/packages/wrangler/src/r2/helpers.ts index 4ddaf2013cec..4813635a73f2 100644 --- a/packages/wrangler/src/r2/helpers.ts +++ b/packages/wrangler/src/r2/helpers.ts @@ -332,11 +332,11 @@ export const R2EventableOperations = [ export type R2EventableOperation = typeof R2EventableOperations[number]; export const actionsForEventCategories: Record< - "object_create" | "object_delete", + "object-create" | "object-delete", R2EventableOperation[] > = { - object_create: ["PutObject", "CompleteMultipartUpload", "CopyObject"], - object_delete: ["DeleteObject"], + "object-create": ["PutObject", "CompleteMultipartUpload", "CopyObject"], + "object-delete": ["DeleteObject"], }; export type R2EventType = keyof typeof actionsForEventCategories; diff --git a/packages/wrangler/src/r2/index.ts b/packages/wrangler/src/r2/index.ts index 5ab048acb8ac..4d88b576f9d2 100644 --- a/packages/wrangler/src/r2/index.ts +++ b/packages/wrangler/src/r2/index.ts @@ -545,7 +545,7 @@ export function r2(r2Yargs: CommonYargsArgv) { ); r2BucketYargs.command( - "event-notification", + "notification", "Manage event notifications for an R2 bucket", (r2EvNotifyYargs) => { return r2EvNotifyYargs @@ -562,7 +562,7 @@ export function r2(r2Yargs: CommonYargsArgv) { }) .option("event-types", { describe: - "Specify the kinds of object events to emit notifications for. ex. '--event-types object_create object_delete'", + "Specify the kinds of object events to emit notifications for. ex. '--event-types object-create object-delete'", alias: "event-type", choices: Object.keys(actionsForEventCategories), demandOption: true,