Skip to content

Commit cccfe51

Browse files
authored
Fix Durable Objects transfer migration validation (#7785)
1 parent 229d00f commit cccfe51

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.changeset/beige-lamps-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix Durable Objects transfer migration validation

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,18 @@ describe("normalizeAndValidateConfig()", () => {
19231923
},
19241924
],
19251925
deleted_classes: ["CLASS_3", "CLASS_4"],
1926+
new_sqlite_classes: ["CLASS_5", "CLASS_6"],
1927+
transferred_classes: [
1928+
{
1929+
from: "FROM_CLASS",
1930+
from_script: "FROM_SCRIPT",
1931+
to: "TO_CLASS",
1932+
},
1933+
{
1934+
from: "FROM_CLASS",
1935+
to: "TO_CLASS",
1936+
},
1937+
],
19261938
unrecognized_field: "FOO",
19271939
},
19281940
],
@@ -1943,7 +1955,8 @@ describe("normalizeAndValidateConfig()", () => {
19431955
`);
19441956
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
19451957
"Processing wrangler configuration:
1946-
- 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\\"}]."
1958+
- 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\\"}].
1959+
- 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\\"}]."
19471960
`);
19481961
});
19491962
});

packages/wrangler/src/config/validation.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,7 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => {
34133413
new_sqlite_classes,
34143414
renamed_classes,
34153415
deleted_classes,
3416+
transferred_classes,
34163417
...rest
34173418
} = rawMigrations[i];
34183419

@@ -3473,6 +3474,33 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => {
34733474
valid = false;
34743475
}
34753476
}
3477+
3478+
if (transferred_classes !== undefined) {
3479+
if (!Array.isArray(transferred_classes)) {
3480+
diagnostics.errors.push(
3481+
`Expected "migrations[${i}].transferred_classes" to be an array of "{from: string, from_script: string, to: string}" objects but got ${JSON.stringify(
3482+
transferred_classes
3483+
)}.`
3484+
);
3485+
valid = false;
3486+
} else if (
3487+
transferred_classes.some(
3488+
(c) =>
3489+
typeof c !== "object" ||
3490+
!isRequiredProperty(c, "from", "string") ||
3491+
!isRequiredProperty(c, "from_script", "string") ||
3492+
!isRequiredProperty(c, "to", "string")
3493+
)
3494+
) {
3495+
diagnostics.errors.push(
3496+
`Expected "migrations[${i}].transferred_classes" to be an array of "{from: string, from_script: string, to: string}" objects but got ${JSON.stringify(
3497+
transferred_classes
3498+
)}.`
3499+
);
3500+
valid = false;
3501+
}
3502+
}
3503+
34763504
valid =
34773505
validateOptionalTypedArray(
34783506
diagnostics,

0 commit comments

Comments
 (0)