Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
12345678910111213141516171819202122import 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<Extract<MarkdownReadResult, { status: 'available' }>, 'nodeIndex'> & { nodeIndex: Extract<NodeIndexResult, { status: 'available' }>}
export async function readText(manager: DocumentManager, url: AutomergeUrl, heads?: Heads): Promise<Extract<TextReadResult, { status: 'available' }>> { 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<AvailableMarkdownRead> { 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}