/** * Runtime validation for form specifications. * * Validates: * - No duplicate field names at the same scope level * - All field references in conditionals point to existing fields */ import type { FormElement } from "@formspec/core"; /** * Validation issue severity levels. * * @public */ export type ValidationSeverity = "error" | "warning"; /** * A validation issue found in a form specification. * * @public */ export interface ValidationIssue { /** Severity of the issue */ severity: ValidationSeverity; /** Human-readable message describing the issue */ message: string; /** Path to the element with the issue (e.g., "group.fieldName") */ path: string; } /** * Result of validating a form specification. * * @public */ export interface ValidationResult { /** Whether the form is valid (no errors, warnings are ok) */ valid: boolean; /** List of validation issues found */ issues: ValidationIssue[]; } /** * Validates a form specification for common issues. * * Checks for: * - Duplicate field names at the root level (warning) * - References to non-existent fields in conditionals (error) * * @example * ```typescript * const form = formspec( * field.text("name"), * field.text("name"), // Duplicate! * when("nonExistent", "value", // Reference to non-existent field! * field.text("extra"), * ), * ); * * const result = validateForm(form.elements); * // result.valid === false * // result.issues contains duplicate and reference errors * ``` * * @param elements - The form elements to validate * @returns Validation result with any issues found * * @public */ export declare function validateForm(elements: readonly FormElement[]): ValidationResult; /** * Logs validation issues to the console. * * @param result - The validation result to log * @param formName - Optional name for the form (for better error messages) * * @public */ export declare function logValidationIssues(result: ValidationResult, formName?: string): void; //# sourceMappingURL=validation.d.ts.map