diff --git a/.changeset/fix-mixed-r2-buckets.md b/.changeset/fix-mixed-r2-buckets.md new file mode 100644 index 0000000000..a89f3467d6 --- /dev/null +++ b/.changeset/fix-mixed-r2-buckets.md @@ -0,0 +1,7 @@ +--- +"miniflare": patch +--- + +fix: allow mixed `r2Buckets` records containing both string and object entries + +Previously, passing an `r2Buckets` config that mixed plain string values and object entries (e.g. `{ MY_BUCKET: "bucket-name", OTHER_BUCKET: { ... } }`) would cause Miniflare to throw an error. Both forms are now accepted and normalised correctly. diff --git a/packages/miniflare/src/plugins/r2/index.ts b/packages/miniflare/src/plugins/r2/index.ts index bdb87adedd..9792145cb7 100644 --- a/packages/miniflare/src/plugins/r2/index.ts +++ b/packages/miniflare/src/plugins/r2/index.ts @@ -26,14 +26,16 @@ import { export const R2OptionsSchema = z.object({ r2Buckets: z .union([ - z.record(z.string()), z.record( - z.object({ - id: z.string(), - remoteProxyConnectionString: z - .custom() - .optional(), - }) + z.union([ + z.string(), + z.object({ + id: z.string(), + remoteProxyConnectionString: z + .custom() + .optional(), + }), + ]) ), z.string().array(), ]) diff --git a/packages/miniflare/test/index.spec.ts b/packages/miniflare/test/index.spec.ts index b97f61fbaa..bd8597da05 100644 --- a/packages/miniflare/test/index.spec.ts +++ b/packages/miniflare/test/index.spec.ts @@ -137,6 +137,18 @@ test("Miniflare: validates options", async ({ expect }) => { ); }); +test("Miniflare: accepts mixed r2Buckets record", () => { + const mf = new Miniflare({ + modules: true, + script: "", + r2Buckets: { + LOCAL_BUCKET: "local-bucket", + REMOTE_BUCKET: { id: "remote-bucket" }, + }, + }); + useDispose(mf); +}); + test("Miniflare: ready returns copy of entry URL", async ({ expect }) => { const mf = new Miniflare({ port: 0,