/** * Model validation utilities for Node.js environments. * * **WARNING: This module is NOT browser-compatible.** * * Provides validation capabilities that leverage the LSP infrastructure * for workspace initialization, import resolution, and document building. * * @module sdk/validator */ /** * Validation diagnostic with file context. */ export interface ValidationDiagnostic { /** Diagnostic severity (1=error, 2=warning, 3=info, 4=hint) */ severity: number; /** Diagnostic message */ message: string; /** File path where diagnostic occurred */ file: string; /** Line number (1-based) */ line: number; /** Column number (1-based) */ column: number; } /** * Result of model validation. */ export interface ValidationResult { /** Whether the model is valid (no errors) */ valid: boolean; /** Number of files validated */ fileCount: number; /** Number of domains in the model */ domainCount: number; /** Number of bounded contexts in the model */ bcCount: number; /** Validation errors */ errors: ValidationDiagnostic[]; /** Validation warnings */ warnings: ValidationDiagnostic[]; } /** * Options for validation. */ export interface ValidationOptions { /** Workspace directory (defaults to file's directory) */ workspaceDir?: string; } /** * Validates a DomainLang model file and all its imports. * * Uses the LSP infrastructure to: * - Initialize the workspace * - Resolve and load imports * - Build and validate all documents * * @param filePath - Path to the entry .dlang file * @param options - Validation options * @returns Validation result with errors, warnings, and model statistics * @throws Error if file doesn't exist or has invalid extension * * @example * ```typescript * import { validateFile } from '@domainlang/language/sdk'; * * const result = await validateFile('./index.dlang'); * * if (!result.valid) { * for (const err of result.errors) { * console.error(`${err.file}:${err.line}:${err.column}: ${err.message}`); * } * process.exit(1); * } * * console.log(`✓ Validated ${result.fileCount} files`); * console.log(` ${result.domainCount} domains, ${result.bcCount} bounded contexts`); * ``` */ export declare function validateFile(filePath: string, options?: ValidationOptions): Promise; /** * Workspace validation result with diagnostics grouped by file. */ export interface WorkspaceValidationResult { /** Whether the workspace is valid (no errors in any file) */ valid: boolean; /** Number of files validated */ fileCount: number; /** Number of domains across all files */ domainCount: number; /** Number of bounded contexts across all files */ bcCount: number; /** Validation errors grouped by file path */ errors: ValidationDiagnostic[]; /** Validation warnings grouped by file path */ warnings: ValidationDiagnostic[]; /** Total number of diagnostics across all files */ totalDiagnostics: number; } /** * Validates an entire DomainLang workspace. * * Uses the LSP infrastructure to: * - Initialize the workspace from a directory containing model.yaml * - Load the entry file (from manifest or default index.dlang) * - Resolve and load all imports * - Build and validate all documents in the workspace * - Collect diagnostics from ALL documents (like VS Code Problems pane) * * @param workspaceDir - Path to the workspace directory (containing model.yaml) * @returns Validation result with diagnostics from all files * @throws Error if workspace directory doesn't exist or cannot be loaded * * @example * ```typescript * import { validateWorkspace } from '@domainlang/language/sdk'; * * const result = await validateWorkspace('./my-workspace'); * * if (!result.valid) { * console.error(`Found ${result.errors.length} errors in ${result.fileCount} files`); * * for (const err of result.errors) { * console.error(`${err.file}:${err.line}:${err.column}: ${err.message}`); * } * process.exit(1); * } * * console.log(`✓ Validated ${result.fileCount} files`); * console.log(` ${result.domainCount} domains, ${result.bcCount} bounded contexts`); * console.log(` 0 errors, ${result.warnings.length} warnings`); * ``` */ export declare function validateWorkspace(workspaceDir: string): Promise;