diff --git a/packages/integrations/markdoc/components/astroNode.ts b/packages/integrations/markdoc/components/astroNode.ts index e9b28e31d..da0ccbd21 100644 --- a/packages/integrations/markdoc/components/astroNode.ts +++ b/packages/integrations/markdoc/components/astroNode.ts @@ -21,7 +21,7 @@ export function createAstroNode( node: RenderableTreeNode, components: Record = {} ): AstroNode { - components = validateComponents(components); + components = validateComponentsProp(components); if (typeof node === 'string' || typeof node === 'number') { return String(node); @@ -53,24 +53,24 @@ export function createAstroNode( } } -function validateComponents(components: Record) { +const componentsPropValidator = z.record( + z + .string() + .min(1, 'Invalid `components` prop. Component names cannot be empty!') + .refine( + (value) => isCapitalized(value), + (value) => ({ + message: `Invalid \`components\` prop: ${JSON.stringify( + value + )}. Component name must be capitalized. If you want to render HTML elements as components, try using a Markdoc node [TODO: DOCS LINK]`, + }) + ), + z.any() +); + +function validateComponentsProp(components: Record) { try { - return z - .record( - z - .string() - .min(1, 'Invalid `components` prop. Component names cannot be empty!') - .refine( - (value) => isCapitalized(value), - (value) => ({ - message: `Invalid \`components\` prop: ${JSON.stringify( - value - )}. Component name must be capitalized. If you want to render HTML elements as components, try using a Markdoc node [TODO: DOCS LINK]`, - }) - ), - z.any() - ) - .parse(components); + return componentsPropValidator.parse(components); } catch (e) { throw new MarkdocError({ message: