import { ParseResult, PackageAPI, PackageInfo, ParseError, DocConfigSource, ExportedFunction, ExportedType, JSDocInfo, JSDocParam, JSDocTag, MDXFrontmatter, ReadmeContent, ReadmeSection, ReExport, SyncError } from '../types.js'; import { ClassDeclaration, EnumDeclaration, FunctionDeclaration, InterfaceDeclaration, TypeAliasDeclaration, Node, JSDocableNode, JSDoc, Project, SourceFile } from 'ts-morph'; import '@bfra.me/es/result'; import 'zod'; /** * @bfra.me/doc-sync/parsers/export-analyzer - Public API surface analyzer for package exports */ /** * Options for analyzing package exports */ interface ExportAnalyzerOptions { readonly tsConfigPath?: string; readonly followReExports?: boolean; readonly maxDepth?: number; } /** * Resolved export information including the original source */ interface ResolvedExport { readonly name: string; readonly kind: 'function' | 'type' | 'interface' | 'enum' | 'class' | 're-export'; readonly source: string; readonly isDefault: boolean; } /** * Complete analysis of a package's public API */ interface PublicAPIAnalysis { readonly packagePath: string; readonly entryPoint: string; readonly api: PackageAPI; readonly resolvedExports: readonly ResolvedExport[]; } /** * Analyzes the public API surface of a package from its entry point */ declare function analyzePublicAPI(entryPointPath: string, options?: ExportAnalyzerOptions): ParseResult; /** * Finds all exported symbols from a package entry point */ declare function findExportedSymbols(entryPointPath: string, options?: ExportAnalyzerOptions): ParseResult; /** * Checks if a symbol is exported from a package */ declare function isSymbolExported(entryPointPath: string, symbolName: string, options?: ExportAnalyzerOptions): ParseResult; /** * Gets detailed information about a specific exported symbol */ declare function getExportedSymbolInfo(entryPointPath: string, symbolName: string, options?: ExportAnalyzerOptions): ParseResult; /** * Filters exports by kind */ declare function getExportsByKind(entryPointPath: string, kind: ResolvedExport['kind'], options?: ExportAnalyzerOptions): ParseResult; /** * @bfra.me/doc-sync/parsers/guards - Type guards and validation for parser types */ declare function isParseError(value: unknown): value is ParseError; /** * Type guard for SyncError */ declare function isSyncError(value: unknown): value is SyncError; declare function isJSDocParam(value: unknown): value is JSDocParam; declare function isJSDocTag(value: unknown): value is JSDocTag; declare function isJSDocInfo(value: unknown): value is JSDocInfo; declare function isExportedFunction(value: unknown): value is ExportedFunction; declare function isExportedType(value: unknown): value is ExportedType; declare function isReExport(value: unknown): value is ReExport; declare function isPackageAPI(value: unknown): value is PackageAPI; declare function isDocConfigSource(value: unknown): value is DocConfigSource; declare function isPackageInfo(value: unknown): value is PackageInfo; declare function isReadmeSection(value: unknown): value is ReadmeSection; declare function isReadmeContent(value: unknown): value is ReadmeContent; declare function isMDXFrontmatter(value: unknown): value is MDXFrontmatter; declare function isValidPackageName(name: string): boolean; declare function isValidSemver(version: string): boolean; declare function isValidHeadingLevel(level: number): level is 1 | 2 | 3 | 4 | 5 | 6; /** Checks for potential XSS patterns to prevent injection attacks */ declare function isSafeContent(content: string): boolean; /** Prevents directory traversal attacks in file paths */ declare function isSafeFilePath(filePath: string): boolean; declare function assertParseError(value: unknown): asserts value is ParseError; declare function assertPackageInfo(value: unknown): asserts value is PackageInfo; declare function assertPackageAPI(value: unknown): asserts value is PackageAPI; /** * @bfra.me/doc-sync/parsers/jsdoc-extractor - JSDoc annotation extraction from TypeScript AST nodes */ /** * Supported node types for JSDoc extraction */ type JSDocableDeclaration = ClassDeclaration | EnumDeclaration | FunctionDeclaration | InterfaceDeclaration | TypeAliasDeclaration; /** * Type guard to check if a node has JSDoc */ declare function hasJSDoc(node: Node): node is Node & JSDocableNode; /** * Extracts JSDoc information from an AST node */ declare function extractJSDocInfo(node: JSDocableDeclaration): JSDocInfo | undefined; /** * Parses a JSDoc node into structured information */ declare function parseJSDoc(jsDoc: JSDoc): JSDocInfo; /** * @bfra.me/doc-sync/parsers/package-info - Package.json metadata extraction */ /** * Schema for validating package.json structure (runtime validation) */ interface PackageJsonSchema { readonly name: string; readonly version: string; readonly description?: string; readonly keywords?: readonly string[]; readonly main?: string; readonly module?: string; readonly types?: string; readonly exports?: Record; readonly repository?: string | { readonly type?: string; readonly url?: string; readonly directory?: string; }; readonly docs?: DocConfigSource; } /** * Options for parsing package.json files */ interface PackageInfoOptions { readonly validateSchema?: boolean; readonly extractDocsConfig?: boolean; } /** * Parses a package.json file and extracts relevant metadata */ declare function parsePackageJson(packagePath: string, options?: PackageInfoOptions): Promise>; /** * Parses package.json content from a string */ declare function parsePackageJsonContent(content: string, filePath: string, options?: PackageInfoOptions): ParseResult; /** * Extracts documentation configuration from package.json */ declare function extractDocsConfig(pkg: PackageInfo): DocConfigSource | undefined; /** * Checks if a README file exists for a package */ declare function findReadmePath(packagePath: string): Promise; /** * Extracts the source entry point from package.json */ declare function findEntryPoint(pkg: PackageInfo, content: string): string; /** * Parses a complete package including README detection */ declare function parsePackageComplete(packagePath: string, options?: PackageInfoOptions): Promise>; /** * Gets the package scope from a scoped package name */ declare function getPackageScope(packageName: string): string | undefined; /** * Gets the unscoped package name */ declare function getUnscopedName(packageName: string): string; /** * Builds a documentation slug from a package name */ declare function buildDocSlug(packageName: string): string; /** * @bfra.me/doc-sync/parsers/readme-parser - README Markdown parser with section extraction */ /** * Options for parsing README files */ interface ReadmeParserOptions { readonly extractSections?: boolean; readonly preserveRaw?: boolean; } /** * Parses a README markdown string into structured content */ declare function parseReadme(content: string, options?: ReadmeParserOptions): ParseResult; /** * Parses a README file from the file system */ declare function parseReadmeFile(filePath: string, options?: ReadmeParserOptions): Promise>; /** * Finds a section by heading text (case-insensitive) */ declare function findSection(content: ReadmeContent, headingText: string): ReadmeSection | undefined; /** * Gets all sections at a specific heading level */ declare function getSectionsByLevel(content: ReadmeContent, level: number): readonly ReadmeSection[]; /** * Flattens all sections into a single array */ declare function flattenSections(content: ReadmeContent): readonly ReadmeSection[]; /** * Gets the table of contents as a flat list */ declare function getTableOfContents(content: ReadmeContent): readonly { readonly heading: string; readonly level: number; }[]; /** * @bfra.me/doc-sync/parsers/typescript-parser - TypeScript source file parser using ts-morph */ /** * Options for parsing TypeScript source files */ interface TypeScriptParserOptions { readonly tsConfigPath?: string; readonly compilerOptions?: Record; } /** * Creates a ts-morph project instance for analyzing source files */ declare function createProject(options?: TypeScriptParserOptions): Project; /** * Parses a TypeScript source file and extracts its structure */ declare function parseSourceFile(project: Project, filePath: string): ParseResult; /** * Parses TypeScript source content from a string */ declare function parseSourceContent(project: Project, content: string, virtualPath?: string): ParseResult; /** * Extracts exported functions from a source file */ declare function extractExportedFunctions(sourceFile: SourceFile): readonly ExportedFunction[]; /** * Extracts exported types and interfaces from a source file */ declare function extractExportedTypes(sourceFile: SourceFile): readonly ExportedType[]; /** * Extracts re-export statements from a source file */ declare function extractReExports(sourceFile: SourceFile): readonly ReExport[]; /** * Extracts the complete API surface from a source file */ declare function extractPackageAPI(sourceFile: SourceFile): PackageAPI; /** * Parses and analyzes a TypeScript file, returning the complete API */ declare function analyzeTypeScriptFile(filePath: string, options?: TypeScriptParserOptions): ParseResult; /** * Analyzes TypeScript content from a string */ declare function analyzeTypeScriptContent(content: string, options?: TypeScriptParserOptions): ParseResult; export { type ExportAnalyzerOptions, type JSDocableDeclaration, type PackageInfoOptions, type PackageJsonSchema, type PublicAPIAnalysis, type ReadmeParserOptions, type ResolvedExport, type TypeScriptParserOptions, analyzePublicAPI, analyzeTypeScriptContent, analyzeTypeScriptFile, assertPackageAPI, assertPackageInfo, assertParseError, buildDocSlug, createProject, extractDocsConfig, extractExportedFunctions, extractExportedTypes, extractJSDocInfo, extractPackageAPI, extractReExports, findEntryPoint, findExportedSymbols, findReadmePath, findSection, flattenSections, getExportedSymbolInfo, getExportsByKind, getPackageScope, getSectionsByLevel, getTableOfContents, getUnscopedName, hasJSDoc, isDocConfigSource, isExportedFunction, isExportedType, isJSDocInfo, isJSDocParam, isJSDocTag, isMDXFrontmatter, isPackageAPI, isPackageInfo, isParseError, isReExport, isReadmeContent, isReadmeSection, isSafeContent, isSafeFilePath, isSymbolExported, isSyncError, isValidHeadingLevel, isValidPackageName, isValidSemver, parseJSDoc, parsePackageComplete, parsePackageJson, parsePackageJsonContent, parseReadme, parseReadmeFile, parseSourceContent, parseSourceFile };