From a049cb2f04defb1c77ab29e2797d508a4a8d536a Mon Sep 17 00:00:00 2001 From: Kratos2k7 Date: Wed, 15 Apr 2026 08:14:26 +0500 Subject: [PATCH] fix: Added wrap as an accepted optional boolean on TextBackground with a description explaining it exists purely so validators can emit a clear migration error. --- schemas/textproperties.yaml | 7 +++++++ scripts/fix-discriminator.cjs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/schemas/textproperties.yaml b/schemas/textproperties.yaml index fc771c7..b902e6f 100644 --- a/schemas/textproperties.yaml +++ b/schemas/textproperties.yaml @@ -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 diff --git a/scripts/fix-discriminator.cjs b/scripts/fix-discriminator.cjs index c7a156f..38b108f 100644 --- a/scripts/fix-discriminator.cjs +++ b/scripts/fix-discriminator.cjs @@ -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); @@ -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); } @@ -682,6 +714,7 @@ const clipClipSchemaWithFitFilter = clipClipSchema.transform((clip) => { } jsContent = addStrictToObjects(jsContent, "z"); + jsContent = addLegacyTextWrapMigrationError(jsContent, "z"); fs.writeFileSync(zodGenJsPath, jsContent); }