/** * StreamingValidator — Streaming validation foundation (G1 / v1.7) * ================================================================= * Validates XML via SAX events without building a DOM tree. * Designed to work alongside (not replace) the DOM-based ValidationEngine. * * v1.7-foundation scope: * ✔ SAX-event consumer interface * ✔ Stack-based element path tracking * ✔ Structural validation (sequence/choice/all) via DfaEngine * ✔ Type validation via TypeValidator * ✔ Occurrence checking * ✔ Stream pipeline helper: validateStream(stream, schema) * * Not yet in v1.7-foundation: * ✗ Identity constraints (xs:key/unique/keyref) — requires full doc * ✗ xs:assert — requires element context * ✗ PSVI — deferred to streaming PSVI spec (v1.9) */ import type { Readable } from 'stream'; import { SchemaModel } from '../schema/SchemaModel'; import { CompiledSchema } from '../pipeline/SchemaCompilerLite'; export interface StreamingValidationOptions { mode?: 'strict' | 'lax'; recover?: boolean; maxErrors?: number; /** * S-03: Maximum number of accumulated xs:key/unique tuples. * Prevents DoS via pathologically large key sets. Default: 50 000. */ maxKeyTuples?: number; /** * Namespace prefix → URI map extracted from the document for xsi:type resolution. * When not supplied the validator will infer it from SAX namespace events. */ namespaceMap?: Map; } export interface StreamingValidationResult { valid: boolean; issues: StreamingIssue[]; errorCount: number; warningCount: number; durationMs: number; } export interface StreamingIssue { severity: 'error' | 'warning'; message: string; path: string; line?: number; col?: number; code?: string; } export interface IValidator { validateString(xml: string): StreamingValidationResult | import('./ValidationResult').ValidationResult; } export declare class StreamingValidator implements IValidator { private readonly _compiled; private readonly _opts; private readonly _tv; constructor(compiled: CompiledSchema, opts?: StreamingValidationOptions); validateString(xml: string): StreamingValidationResult; private _resolveDecl; private _resolveType; /** * T-02 / S-01: Resolve an xsi:type value to a ComplexTypeDefinition with: * • prefix→namespace resolution using the accumulated nsMap * • simple-type fallback (returns undefined — caller keeps existing typeDef) * • type-safety check: the resolved type must be derived from the declared type */ private _resolveXsiType; /** * S-01 helper: check whether `typeDef` is derived (directly or transitively) * from `baseTypeName` via the schema's complex type hierarchy. */ private _isDerivedFrom; private _validateAttributes; private _validateContent; private _validateSimpleType; private _validateChildOrder; } /** * Options for StreamingKeyrefTracker. */ export interface StreamingKeyrefTrackerOptions { /** * S-03: Maximum number of accumulated key/keyref tuples across all constraints. * When exceeded the tracker stops collecting new tuples and emits a warning. * Default: 50 000. */ maxTuples?: number; } /** * Streaming-aware xs:key / xs:unique / xs:keyref tracker. * Accumulates key/keyref tuples in a single SAX pass and validates * referential integrity once the document end is reached. * * T-01 fix: improved XPath selector parsing supporting: * - bare element names: `item` * - descendant step: `.//item`, `.//a/b` (last step matched) * - child:: axis: `child::item` * - pipe-delimited union: `item|other` * * S-03 fix: bounded tuple accumulation via `maxTuples` option. * * Usage: * const tracker = new StreamingKeyrefTracker(schema, { maxTuples: 50000 }); * // During SAX: tracker.onElement(localName, path, attrs, textContent) * // After parse: tracker.validate() → StreamingIssue[] */ export declare class StreamingKeyrefTracker { /** key-name → set of serialised field tuples */ private _keys; /** keyref-name → list of {refer, tuples[]} to check */ private _keyrefs; /** NP0-02: accumulated duplicate key/unique violations */ private _duplicateViolations; private readonly _allConstraints; /** item 9: element-name → constraints index for O(1) lookup */ private readonly _constraintsByElement; /** S-03: Total accumulated tuple count */ private _tupleCount; private readonly _maxTuples; private _tupleCapExceeded; constructor(schema: SchemaModel, opts?: StreamingKeyrefTrackerOptions); /** * T-01: Extract element local names that a selector expression can match. * Handles: bare names, `.//name`, `.//a/b` (last segment), `child::name`, * `name|other` (union), and `*` wildcard. * * Returns an array of local names. Callers register constraints under each name. */ private _extractSelectorNames; /** * Called for each element's text content during SAX processing. * A simplified field resolver: for single-field constraints where * the field is '.' (text content) or an attribute reference '@attr'. */ onElement(localName: string, _path: string, attrs: Array<{ name: string; value: string; }>, textContent: string): void; /** Validate keyref → key/unique references. Returns issues. */ validate(): StreamingIssue[]; } /** * Validate an XML string against a compiled schema using streaming (SAX) validation. * Does not build a DOM tree. */ export declare function validateStreaming(xmlSource: string, compiled: CompiledSchema, opts?: StreamingValidationOptions): StreamingValidationResult; /** * Validate a Node.js Readable stream against a compiled schema. * Accumulates chunks then validates — true chunk-at-a-time streaming is v2.0. */ export declare function validateStream(stream: Readable, compiled: CompiledSchema, opts?: StreamingValidationOptions): Promise; /** * Streaming validation result as an async generator (P2 — v1.7 foundation). * * Emits each `StreamingIssue` as it is produced so that callers can react * (e.g. log or abort) without waiting for the full document to be validated. * * The generator yields issues in document order. After all issues have been * yielded the generator returns the final `StreamingValidationResult` via * the `return` value (accessible via `generator.return()`). * * @example * for await (const issue of validateStreamingGenerator(xml, compiled)) { * console.error(issue.message); * } */ export declare function validateStreamingGenerator(xmlSource: string, compiled: CompiledSchema, opts?: StreamingValidationOptions): AsyncGenerator; //# sourceMappingURL=StreamingValidator.d.ts.map