import type { AutomergeUrl } from '../storage/document-runtime-contract' import type { DocumentManager, MarkdownReadResult, TextReadResult } from '../services/document-manager' import type { Heads } from '../sync/heads' import type { NodeIndexResult } from '../automerge-markdown' type AvailableMarkdownRead = Omit, 'nodeIndex'> & { nodeIndex: Extract } export async function readText(manager: DocumentManager, url: AutomergeUrl, heads?: Heads): Promise> { const result = await manager.readText(url, heads) if (result.status !== 'available') throw new Error(`Expected text at ${url}, got ${result.status}`) return result } export async function readMarkdown(manager: DocumentManager, url: AutomergeUrl, heads?: Heads): Promise { const result = await manager.readMarkdown(url, heads) if (result.status !== 'available') throw new Error(`Expected Markdown at ${url}, got ${result.status}`) if (result.nodeIndex.status !== 'available') throw new Error(`Expected indexed Markdown at ${url}`) return result as AvailableMarkdownRead }