UNPKG

@stacksjs/dtsx

Version:

A modern, fast .d.ts generation tool, powered by Bun.

114 lines (113 loc) 3.99 kB
import type { DtsError, SourceLocation } from './types'; /** * Type guards for error types */ export declare function isDtsxError(error: unknown): error is DtsxError; export declare function isParseError(error: unknown): error is ParseError; export declare function isFileError(error: unknown): error is FileError; export declare function isConfigError(error: unknown): error is ConfigError; /** * Wrap an unknown error in a DtsxError */ export declare function wrapError(error: unknown, code?: ErrorCode, message?: string): DtsxError; /** * Calculate line and column from source code offset */ export declare function getLocationFromOffset(sourceCode: string, offset: number): SourceLocation; /** * Create a formatted error message with source location context */ export declare function formatErrorWithContext(sourceCode: string, location: SourceLocation, message: string, filePath?: string): string; /** * Create a DtsError from an exception */ export declare function createDtsError(error: unknown, file: string, _sourceCode?: string): DtsError; /** * Format a DtsError for display */ export declare function formatDtsError(error: DtsError, sourceCode?: string): string; /** * Aggregate multiple errors into a summary */ export declare function summarizeErrors(errors: DtsError[]): string; /** * Error codes for categorizing errors */ export declare const ErrorCodes: { PARSE_ERROR: 'PARSE_ERROR'; SYNTAX_ERROR: 'SYNTAX_ERROR'; FILE_NOT_FOUND: 'FILE_NOT_FOUND'; FILE_READ_ERROR: 'FILE_READ_ERROR'; FILE_WRITE_ERROR: 'FILE_WRITE_ERROR'; TYPE_INFERENCE_ERROR: 'TYPE_INFERENCE_ERROR'; UNRESOLVED_TYPE: 'UNRESOLVED_TYPE'; EXTRACTION_ERROR: 'EXTRACTION_ERROR'; PROCESSING_ERROR: 'PROCESSING_ERROR'; VALIDATION_ERROR: 'VALIDATION_ERROR'; INVALID_DECLARATION: 'INVALID_DECLARATION'; CONFIG_ERROR: 'CONFIG_ERROR'; INVALID_ENTRYPOINT: 'INVALID_ENTRYPOINT'; CIRCULAR_DEPENDENCY: 'CIRCULAR_DEPENDENCY'; TIMEOUT_ERROR: 'TIMEOUT_ERROR'; NOT_SUPPORTED: 'NOT_SUPPORTED'; UNKNOWN_ERROR: 'UNKNOWN_ERROR' }; export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes]; /** * Base error class for dtsx errors */ export declare class DtsxError extends Error { readonly code: ErrorCode; readonly context?: Record<string, unknown>; constructor(message: string, code?: ErrorCode, context?: Record<string, unknown>); toString(): string; toJSON(): Record<string, unknown>; } /** * Error during file parsing */ export declare class ParseError extends DtsxError { readonly filePath: string; readonly line?: number; readonly column?: number; constructor(message: string, filePath: string, options?: { line?: number, column?: number, cause?: Error }); get locationString(): string; } /** * Error during declaration extraction */ export declare class ExtractionError extends DtsxError { readonly filePath: string; readonly declarationKind?: string; constructor(message: string, filePath: string, declarationKind?: string, cause?: Error); } /** * Error during type processing */ export declare class ProcessingError extends DtsxError { readonly declarationName?: string; constructor(message: string, declarationName?: string, cause?: Error); } /** * Error during file I/O operations */ export declare class FileError extends DtsxError { readonly filePath: string; readonly operation: 'read' | 'write' | 'delete' | 'stat' | 'glob'; constructor(message: string, filePath: string, operation: 'read' | 'write' | 'delete' | 'stat' | 'glob', cause?: Error); } /** * Error during configuration loading or validation */ export declare class ConfigError extends DtsxError { readonly configPath?: string; readonly invalidKey?: string; constructor(message: string, options?: { configPath?: string, invalidKey?: string, cause?: Error }); } /** * Error when circular dependency is detected */ export declare class CircularDependencyError extends DtsxError { readonly cycle: string[]; constructor(cycle: string[]); }