import type { Document } from "@contentful/rich-text-types"; type GraphqlRichText = { json: Document; links?: unknown }; const isDocument = (v: unknown): v is Document => !!v && typeof v === "object" && "nodeType" in (v as any) && "content" in (v as any); export const toDocument = (v: unknown | null | undefined): Document | null => { if (!v) return null; // REST/CDA Document if (isDocument(v)) return v; // GraphQL RichText { json: Document, links? } if (typeof v === "object" && v !== null && "json" in (v as any)) { const json = (v as GraphqlRichText).json; return isDocument(json) ? json : null; } return null; };