From cccfe51ca6a18a2a69bb6c7fa7066c92c9d704af Mon Sep 17 00:00:00 2001 From: Josh Howard Date: Tue, 21 Jan 2025 08:16:02 -0600 Subject: [PATCH] Fix Durable Objects transfer migration validation (#7785) --- .changeset/beige-lamps-leave.md | 5 ++++ .../__tests__/config/configuration.test.ts | 15 +++++++++- packages/wrangler/src/config/validation.ts | 28 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .changeset/beige-lamps-leave.md diff --git a/.changeset/beige-lamps-leave.md b/.changeset/beige-lamps-leave.md new file mode 100644 index 000000000000..35222439ac40 --- /dev/null +++ b/.changeset/beige-lamps-leave.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Fix Durable Objects transfer migration validation diff --git a/packages/wrangler/src/__tests__/config/configuration.test.ts b/packages/wrangler/src/__tests__/config/configuration.test.ts index d720b0088bdc..6d5eb998d125 100644 --- a/packages/wrangler/src/__tests__/config/configuration.test.ts +++ b/packages/wrangler/src/__tests__/config/configuration.test.ts @@ -1923,6 +1923,18 @@ describe("normalizeAndValidateConfig()", () => { }, ], deleted_classes: ["CLASS_3", "CLASS_4"], + new_sqlite_classes: ["CLASS_5", "CLASS_6"], + transferred_classes: [ + { + from: "FROM_CLASS", + from_script: "FROM_SCRIPT", + to: "TO_CLASS", + }, + { + from: "FROM_CLASS", + to: "TO_CLASS", + }, + ], unrecognized_field: "FOO", }, ], @@ -1943,7 +1955,8 @@ describe("normalizeAndValidateConfig()", () => { `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]." + - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]. + - Expected \\"migrations[0].transferred_classes\\" to be an array of \\"{from: string, from_script: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"from_script\\":\\"FROM_SCRIPT\\",\\"to\\":\\"TO_CLASS\\"},{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"}]." `); }); }); diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index 581fbb4d2de0..c1f4db139fcc 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -3413,6 +3413,7 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => { new_sqlite_classes, renamed_classes, deleted_classes, + transferred_classes, ...rest } = rawMigrations[i]; @@ -3473,6 +3474,33 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => { valid = false; } } + + if (transferred_classes !== undefined) { + if (!Array.isArray(transferred_classes)) { + diagnostics.errors.push( + `Expected "migrations[${i}].transferred_classes" to be an array of "{from: string, from_script: string, to: string}" objects but got ${JSON.stringify( + transferred_classes + )}.` + ); + valid = false; + } else if ( + transferred_classes.some( + (c) => + typeof c !== "object" || + !isRequiredProperty(c, "from", "string") || + !isRequiredProperty(c, "from_script", "string") || + !isRequiredProperty(c, "to", "string") + ) + ) { + diagnostics.errors.push( + `Expected "migrations[${i}].transferred_classes" to be an array of "{from: string, from_script: string, to: string}" objects but got ${JSON.stringify( + transferred_classes + )}.` + ); + valid = false; + } + } + valid = validateOptionalTypedArray( diagnostics,