/** * JSON-LD style properties that can appear on any object in flat mode */ interface LDProperties { $id?: string; $type?: string | string[]; $context?: string | string[] | Record; } /** * Data object with optional JSON-LD properties */ type MDXLDData = LDProperties & Record; /** * Helper type to create typed data with $type discriminator * Used by extension packages (schema.org.ai, business.org.ai) to create discriminated unions * * @example * ```ts * // In schema.org.ai package: * type ArticleData = TypedData<'Article', { headline: string; author: string }> * type PersonData = TypedData<'Person', { name: string; email: string }> * type SchemaOrgData = ArticleData | PersonData * ``` */ type TypedData = Record> = { $type: TType; } & Omit & TFields; /** * Helper to extract $type literal from typed data */ type ExtractType = T extends { $type: infer TType; } ? TType : string | string[]; /** * Root MDXLD document structure with generic data type support * * @typeParam TData - The type of the data object, defaults to MDXLDData * * @example * ```ts * // Basic usage * const doc: MDXLDDocument = parse(content) * * // With typed data from extension package * import { SchemaOrgData } from 'schema.org.ai' * const doc: MDXLDDocument = parse(content) as MDXLDDocument * ``` */ interface MDXLDDocument { /** Document identifier (maps to $id in flat mode) */ id?: string; /** Document type (maps to $type in flat mode) */ type?: ExtractType; /** JSON-LD context (maps to $context in flat mode) */ context?: string | string[] | Record; /** Structured data from YAML frontmatter */ data: TData; /** Raw MDX content body */ content: string; } /** * Type guard to check if document has a specific $type * * @example * ```ts * if (isType(doc, 'Article')) { * // doc.type is 'Article', doc.data.$type is 'Article' * } * ``` */ declare function isType(doc: MDXLDDocument, type: T): doc is MDXLDDocument>; /** * Type guard to check if document has one of multiple types */ declare function isOneOfTypes(doc: MDXLDDocument, types: T): doc is MDXLDDocument>; /** * Create a typed document factory for a specific type * * @example * ```ts * const createArticle = createTypedDocument('Article') * const article = createArticle({ headline: 'Hello', author: 'John' }, '# Content') * ``` */ declare function createTypedDocument(type: ExtractType): (data: Omit, content: string) => MDXLDDocument; /** * Extended document with AST (added by mdxld/ast) */ interface MDXLDDocumentWithAST extends MDXLDDocument { /** Parsed AST representation */ ast: MDXLDAst; } /** * Extended document with compiled code (added by mdxld/compile) */ interface MDXLDDocumentWithCode extends MDXLDDocument { /** Compiled JavaScript code */ code: string; /** React component (when evaluated) */ component?: unknown; } /** * Fully extended document with all properties */ interface MDXLDDocumentFull extends MDXLDDocument { ast?: MDXLDAst; code?: string; component?: unknown; } /** * AST node types */ type MDXLDAstNodeType = 'root' | 'yaml' | 'paragraph' | 'heading' | 'text' | 'emphasis' | 'strong' | 'inlineCode' | 'code' | 'link' | 'image' | 'list' | 'listItem' | 'blockquote' | 'thematicBreak' | 'html' | 'mdxJsxFlowElement' | 'mdxJsxTextElement' | 'mdxFlowExpression' | 'mdxTextExpression' | 'mdxjsEsm'; /** * Base AST node */ interface MDXLDAstNode { type: MDXLDAstNodeType | string; children?: MDXLDAstNode[]; value?: string; position?: { start: { line: number; column: number; offset: number; }; end: { line: number; column: number; offset: number; }; }; [key: string]: unknown; } /** * Root AST node */ interface MDXLDAst extends MDXLDAstNode { type: 'root'; children: MDXLDAstNode[]; } /** * Parse options */ interface ParseOptions { /** * Output mode for data properties * - 'expanded': Use id, type, context at root level (default) * - 'flat': Keep $id, $type, $context in data object */ mode?: 'expanded' | 'flat'; } /** * Stringify options */ interface StringifyOptions { /** * Output mode for YAML frontmatter * - 'expanded': Read from id, type, context and write as $id, $type, $context * - 'flat': Write data object as-is with $id, $type, $context */ mode?: 'expanded' | 'flat'; } export { type ExtractType, type LDProperties, type MDXLDAst, type MDXLDAstNode, type MDXLDAstNodeType, type MDXLDData, type MDXLDDocument, type MDXLDDocumentFull, type MDXLDDocumentWithAST, type MDXLDDocumentWithCode, type ParseOptions, type StringifyOptions, type TypedData, createTypedDocument, isOneOfTypes, isType };