/** * ValidationEngine (v1.6 update) * ────────────────────────────────── * Validates an XmlDocument against a SchemaModel. * * v1.4 additions * ─────────────── * • G41 – strict / lax validation mode * strict (default): unknown elements/attributes are errors * lax: unknown elements/attributes are warnings * • G43 – error recovery mode * recover: true → continue past structural errors to collect more issues * • G44 – profiling hooks * profile: true → per-stage timing emitted via ProfileEvent * • G37 – every ValidationIssue now carries `category` + `code` * • Improved error messages with element path and occurrence info * * v1.6 additions * ─────────────── * • G2 – source-mapped error locations: every _addError call now threads * the relevant XmlElement so that sourceLine/sourceCol are propagated * into ValidationIssue for IDE/code-frame use. * * v1.7.0 performance * ─────────────────── * • _mergeComplexTypeChain memoized per validate() call — deep inheritance * chains now computed once per type, not once per element. * • _substitutableDecls memoized per validate() call. * • _getXsiAttr: fast-path via direct map lookup (xsi: prefix or xsi-ns) * before falling back to linear scan. * • AssertionEvaluator module-level import — eliminates repeated require() * overhead inside hot _validateComplexElement path. * • PSVI annotations pooled (see Psvi.ts) — no new object per complex element. */ import { SchemaModel } from '../schema/SchemaModel'; import { XmlDocument, XmlElement } from '../parser/XmlNodes'; import { ValidationResult } from './ValidationResult'; export interface ProfileEvent { stage: string; path: string; durationMs: number; } export interface ValidationOptions { /** Collect all errors instead of stopping at first (default: true) */ collectAll?: boolean; /** * G41 — Validation mode. * 'strict' (default): unknown elements/attributes are errors. * 'lax': unknown elements/attributes produce warnings only. */ mode?: 'strict' | 'lax'; /** * G43 — Error recovery. * When true, validation continues after structural errors to collect more * issues. Required for IDE integrations. Default: false. */ recover?: boolean; /** * G44 — Profiling. * When true, a `profile` array is populated on the ValidationResult with * per-element timing. Default: false. */ profile?: boolean; /** Callback invoked for each profiling event (optional listener). */ onProfile?: (event: ProfileEvent) => void; /** * G45 — Fragment/incremental validation. * When set, treat the validated element as if it were declared with this * named type in the schema, enabling sub-tree validation without a root. */ rootType?: string; /** * G29 — Post-Schema-Validation Infoset. * When true, each validated element is annotated with its resolved XSD type, * normalised value, and validity. Accessible via ValidationResult.psvi. */ psvi?: boolean; } export declare class ValidationEngine { private schema; private tv; private ids; private idrefs; private result; private opts; /** G44 profiling events */ private profileEvents; /** G29 PSVI accumulator */ private _psviMap?; /** * v1.7.0: per-validate() memoization caches. * Both are reset in validate() / validateSubtree() to avoid stale entries * if the same engine instance is reused across different documents. */ private _mergeCache; private _substCache; constructor(schema: SchemaModel, options?: ValidationOptions); validate(doc: XmlDocument): ValidationResult; /** * G45 — Validate a single XmlElement subtree without requiring a full document. * If `rootType` is provided in options, the element is treated as if declared * with that type. Otherwise the engine looks up a top-level element declaration * by the element's local name. */ validateSubtree(elem: XmlElement, path?: string): ValidationResult; /** G44: Return profiling events from the last validate() call */ get lastProfileEvents(): readonly ProfileEvent[]; private _validateElement; private _validateSimpleElement; private _validateComplexElement; private _assertElement; private _validateAttributes; private _validateCompositorTop; private _validateSequence; private _validateChoice; private _validateAll; private _matchParticle; private _matchAny; private _matchElement; private _matchGroup; private _addError; private _addWarning; /** G44: emit profiling event */ private _emitProfile; private _checkIdentityConstraint; private _checkUniqueTuples; private _evalSelector; /** NP0-16 helper: collect all descendant elements matching localName (or * for all). */ private _findDescendants; private _evalField; private _resolveEffectiveType; private _mergeComplexTypeChain; private _substitutableDecls; private _resolveElementDecl; private _getXsiAttr; private _simpleTypeLookupKey; private _simpleTypeToName; } export declare function validate(doc: XmlDocument, schema: SchemaModel, options?: ValidationOptions): ValidationResult; /** * G45 — Validate a single element subtree against a schema. * @param elem The element to validate (may be from a parsed document or * constructed manually). * @param schema The compiled SchemaModel to validate against. * @param options Same options as `validate()` plus `rootType` to force the * declared type (useful when the element is not a top-level * schema declaration). */ export declare function validateSubtree(elem: XmlElement, schema: SchemaModel, options?: ValidationOptions): ValidationResult; /** * G45 — Parse an XML fragment string and validate it as a subtree. * The fragment must be a single root element (no XML declaration required). * * @example * const result = validateFragment('abc', schema, { * rootType: 'xs:decimal', * }); */ export declare function validateFragment(xmlFragment: string, schema: SchemaModel, options?: ValidationOptions): ValidationResult; /** * G38 — Incremental / partial validation: re-validate a subtree rooted at * `elem` and return only the issues found within that subtree. * * This is the primary API for editor "lint on edit" integrations where only * a changed subtree needs to be re-checked. Identity constraints are * evaluated only within the subtree scope (cross-subtree keyrefs are not * checked — callers must run a full `validate()` for referential integrity). * * @param elem The subtree root to re-validate. * @param schema The schema to validate against. * @param options Standard ValidationOptions (psvi, mode, recover, etc.). * @returns A ValidationResult scoped to the subtree. */ export declare function revalidateSubtree(elem: XmlElement, schema: SchemaModel, options?: ValidationOptions): ValidationResult; //# sourceMappingURL=ValidationEngine.d.ts.map