Skip to content

Commit

Permalink
Fix Durable Objects transfer migration validation (#7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshthoward authored Jan 21, 2025
1 parent 229d00f commit cccfe51
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/beige-lamps-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fix Durable Objects transfer migration validation
15 changes: 14 additions & 1 deletion packages/wrangler/src/__tests__/config/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
Expand All @@ -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\\"}]."
`);
});
});
Expand Down
28 changes: 28 additions & 0 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,7 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => {
new_sqlite_classes,
renamed_classes,
deleted_classes,
transferred_classes,
...rest
} = rawMigrations[i];

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cccfe51

Please sign in to comment.