Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions schemas/textproperties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
type: number
minimum: 0
example: 5
wrap:
description: >-
Not supported on legacy `text` assets. Accepted here only so validators
can emit a clear migration error pointing users to `rich-text` or
`rich-caption`, which support background wrapping natively.
type: boolean
example: false
additionalProperties: false
type: object

Expand Down
33 changes: 33 additions & 0 deletions scripts/fix-discriminator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,38 @@ function addStrictToObjects(src, prefix) {
}


function addLegacyTextWrapMigrationError(code, zPrefix) {
const schemaName = 'textassetTextAssetSchema';
const idx = code.indexOf(schemaName);
if (idx === -1) {
console.log("⚠ Could not find " + schemaName);
return code;
}

const strictMarker = '.strict()';
const strictIdx = code.indexOf(strictMarker, idx);
if (strictIdx === -1 || strictIdx - idx > 3000) {
console.log("⚠ Could not find .strict() for " + schemaName);
return code;
}

const superRefine = strictMarker + '.superRefine((data, ctx) => {\n' +
' if (data.background && data.background.wrap === true) {\n' +
' ctx.addIssue({\n' +
' code: ' + zPrefix + '.ZodIssueCode.custom,\n' +
' message: "background.wrap is only supported on rich-text and rich-caption assets. For type \\"text\\", migrate to type \\"rich-text\\" to use this feature.",\n' +
' path: ["background", "wrap"],\n' +
' });\n' +
' }\n' +
'})';

code = code.substring(0, strictIdx) + superRefine + code.substring(strictIdx + strictMarker.length);
console.log("✓ Added legacy-text wrap migration error (" + zPrefix + ")");
return code;
}

content = addStrictToObjects(content, "z");
content = addLegacyTextWrapMigrationError(content, "z");

fs.writeFileSync(zodGenPath, content);

Expand Down Expand Up @@ -550,6 +581,7 @@ const clipClipSchemaWithFitFilter = exports.clipClipSchema.transform((clip) => {
}

cjsContent = addStrictToObjects(cjsContent, "zod_1.z");
cjsContent = addLegacyTextWrapMigrationError(cjsContent, "zod_1.z");

fs.writeFileSync(zodGenCjsPath, cjsContent);
}
Expand Down Expand Up @@ -682,6 +714,7 @@ const clipClipSchemaWithFitFilter = clipClipSchema.transform((clip) => {
}

jsContent = addStrictToObjects(jsContent, "z");
jsContent = addLegacyTextWrapMigrationError(jsContent, "z");

fs.writeFileSync(zodGenJsPath, jsContent);
}
Expand Down
Loading