Skip to content

Commit

Permalink
Improvements to R2 notification commands (#5416)
Browse files Browse the repository at this point in the history
Change `event-notification` subcmd to `notification`

Use `object-{create,delete}`, not `_{delete,create}`

Add changeset
  • Loading branch information
mattdeboard committed Mar 27, 2024
1 parent 7115568 commit 47b325a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .changeset/yellow-wolves-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": minor
---

fix: minor improvements to R2 notification subcommand

1. `r2 bucket event-notification <subcommand>` becomes `r2 bucket notification <subcommand>`
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.
32 changes: 14 additions & 18 deletions packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe("r2", () => {
Manage R2 buckets
Commands:
wrangler r2 bucket create <name> Create a new R2 bucket
wrangler r2 bucket list List R2 buckets
wrangler r2 bucket delete <name> 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 <name> Create a new R2 bucket
wrangler r2 bucket list List R2 buckets
wrangler r2 bucket delete <name> 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]
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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(
" "
)}`
)
Expand All @@ -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 <bucket>
wrangler r2 bucket notification create <bucket>
Create new event notification configuration for an R2 bucket
Expand All @@ -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]"
Expand Down Expand Up @@ -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(`
Expand All @@ -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 <bucket>
wrangler r2 bucket notification delete <bucket>
Delete event notification configuration for an R2 bucket and queue
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/r2/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/r2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export function r2(r2Yargs: CommonYargsArgv) {
);

r2BucketYargs.command(
"event-notification",
"notification",
"Manage event notifications for an R2 bucket",
(r2EvNotifyYargs) => {
return r2EvNotifyYargs
Expand All @@ -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,
Expand Down

0 comments on commit 47b325a

Please sign in to comment.